Google Answers Logo
View Question
 
Q: Perl Programming ( Answered,   2 Comments )
Question  
Subject: Perl Programming
Category: Computers
Asked by: kf20-ga
List Price: $10.00
Posted: 04 Jun 2005 21:47 PDT
Expires: 04 Jul 2005 21:47 PDT
Question ID: 529452
1) Write a statement to determines the number of characters stored in
the $bingo variable, and then assigns the result to the $numbers
variable.


3) Assume $num is 10. Which statement prints the following? 
	100 81 64 49 36 25 16 9 4 1

	a.   while ($num > 0) { print $num * $num, ? ?; }

	b.   while ($num != 0) { print ?$num * $num ?; $num--; }

	c.   while ($num >= 1) { print $num * $num, ? ?; $num--; }

	d.   while ($num > 0) { $num--; print $num * $num, ? ?; }

4) What?s printed by the following code? 
	$num = 20;
	while ($num < 30) {
	   $num++;
	    next if ($num % 3) == 0;
	    last if $num == 19;
	    if (($num % 2) == 0) { $num += 3; } else { $num -= 3; }
	    print $num;
}

5) What does these LINE do? 

   $x = @array;


6) Write a program that takes the user input and if the user entered
word contains "print" (check for case sensitive) or "%" symbol then
attach the word "print" with "***" and "###" for "%" symbol.
[For example - if the user enters "Print the following" then the
output should be "*** Print the following".
Also if the input is "Average score is 60%", then the output should be
"### Average age is 65%".]
Answer  
Subject: Re: Perl Programming
Answered By: leapinglizard-ga on 05 Jun 2005 11:54 PDT
 
Dear kf20,

There are numerous errors in the Comment supplied below. Here are the
correct answers.


1.

The statement is

  $numbers = length($bingo);

which you can test by executing the following code.

  $bingo = "abcdef";
  $numbers = length($bingo);
  print $numbers, "\n";


3.

Only statement (c) provides the desired result.


4.

The loop prints the values 25 and 29 before quitting.


5.

This line assigns the length of the array named @array to the variable $x.


6.

The following code carries out case-insensitive matching for the
string "print". If both "print" and "%" are present in the input
string, then both "***" and "###" are prepended to the echo.

  $line = <STDIN>;
  if ($line =~ /print/i) {
    $line = "*** ".$line;
  }
  if ($line =~ /\%/) {
    $line = "### ".$line;
  }
  print $line;


Regards,

leapinglizard
Comments  
Subject: Re: Perl Programming
From: linuxgeeknerd-ga on 05 Jun 2005 02:30 PDT
 
1) $numbers = length ($bingo);
2) b) and c)
3) 2529
4)$x stores the size of @array
5)only a quick hack:

#!/usr/bin/perl
print "Input: ";
$input = <STDIN>;
if (($input =~ /the/) || ($input =~ /The/)) {
print "***", $input;
}
if($input =~ /\%/) {
print "###", $input;
}
Subject: Re: Perl Programming
From: vladimir-ga on 05 Jun 2005 10:19 PDT
 
The piece of code in point 2/3 b) doesn't produce the expected output,
notice the quotes in print!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy