CSC 220: Lab Two


I) Go to the following website, and read about Perl:


http://perldoc.perl.org/perlintro.html



II) To do the tasks found in the next step, you will need to log onto the altair server. Laboratory one contains the instructions for performing this operation. Also, you will need to use a text editor to write your programs. Finally, look at the instructions in the tutorial above for running programs in Perl.



III) Based on what you read, try the following:


A) Write a program that will display "Coffee is good".

B) Write a program that will add the numbers 58 and 42, then print the result.

C) Write a program that will load an array with the following numbers: 22, 44, 66. Then have the program print all the numbers.
(See the example under the heading for "arrays".)

Note: Write your programs using a text editor, save the file as with a .pl extension. To run Perl at the command prompt of the
terminal, type "perl" (without the quotes, followed by a space, and then the name of the file where you stored the program.



D) Cut and paste the following program into a text editor window and save it:




print "Enter a temperature in Celsius:\n";

$celsius = <STDIN>;

chop($celsius);

if($celsius =~m/^[0-9]+$/) {

     $fahrenheit = ($celsius * 9/5 + 32);
     print "$celsius C = $fahrenheit F\n";
   }

 else {

     print "Expecting a number, so don't understand\"$celsius\".\n";
}


NOW,

    1) Run the program - what does it do?

    2) Study the code - what do you think each line does?

    3) Revise the program to convert from fahrenheit to celsius. The formula is:
    (°F  -  32)  x  5/9 = °C



E) Cut and paste the following program into a text window and save it:


print "Please enter a string:\n";
$input = <STDIN>;
chop($input);
if ($input =~ m/^[aA-zZ]+$/) {

    print "Input has only letters";
   
    }
   
    else {
   
    print "Input has other characters";
    }
   

Now,

    1) Run the program - what does it do?

    2) Study the code - what do you think each line does?