CGS3990, Fall 1998, Perl Assignment 1
Due Thursday 9/3 at the start of class
Read chapter 2 of the Perl book. Write a PERL script that will do the following
-
Prompt the user and read in two scalar values.
-
Display the values as they were entered, but within double quotes so that
any leading or trailing white space will be identifiable.
-
Use chomp on each scalar and display them again, as above.
-
Display each scalar as a number, and display the sum of the two numbers.
-
Treat the scalars as strings and print their concatenation. (Use the .
operator).
-
Treat the first scalar as a string and the second as a number and print the
first repeated the second number of times. (Use the x operator).
Here is a sample of the output
Please enter something: 12we3
Please enter something else: 3er4
Here is the input
something: "12we3
"
something else: "3er4
"
Here is input after chomp
something: "12we3"
something else: "3er4"
Here is the input treated as numbers
something: "12"
something else: "3"
12 + 3 = 15
Here is the input treated as strings, and concatenated
"12we3" . "3er4" = 12we33er4
Here is the first repeated the second number of times
"12we3" x "3" = "12we312we312we3"
Where is Perl????
On solix the command for Perl will be
#!/home/sol2/bin/perl
On mongoose the command for Perl will be
#!/usr/local/bin/perl
Creating and Running the program
-
Use either the pico editor or the
emacs editor to type in your program
-
Exit back to the shell, and change the mode of your file to 700
chmod 700 hw1.pl
-
Now, to run the program, just type its name at the prompt
-
If there are errors, then reopen the editor and make the corrections, then
try to run it again. However, you only have to do the chmod command
once.
Handing it in
-
Be sure that your name, section, and oath attesting that you did the work
on your own are included at the start of your file as comments.
-
To create a listing, use the script command
from solix.
-
Enter the command
script
-
Use the cat command to display the file
cat hw1.pl
-
Run the program several times with different input
-
Type exit to end the script session
-
Print out the typescript file using
lpr. Hand in the printout.