Question: Working with data this is all in PERL 1. Some exercises require you to ask the user for data. This is achieved with the print
Working with data this is all in PERL
| 1. | Some exercises require you to ask the user for data. This is achieved with the print command to show the prompt, then by reading, the standard input channel, into a variable. Finally, the line termination character/s are removed using chomp. We will be covering all this later, but for now the method is shown in this example: |
| print "Enter a first name: "; # The prompt (no new-line) $name = | |
| a) Using the code fragment above as a guide, prompt the user for a first name then a last name, storing these in different scalar variables. b) Now put the first and last names into a hash, using the keys 'first' and 'last'. Is it possible to print the hash? c) Dump the hash into the array, using a single assignment, and print the array again. Can you explain what is printed? | |
| 2. | Create an array @numbers with the five numbers: 1, 5, 9, 3.14159 and 2. Print it with and without interpolation ("@numbers" and @numbers), and note differences. |
| 3. | Create a hash that contains the following first-name => last-name pairs: |
| John Norman Robert Anson Christopher Fowler Robert Harris Dan Simmons | |
| Now add code to prompt for a first name. Use the reply to obtain the last name from the hash, and print the full name. | |
| 4. | Create an array from a list of eight computer names: |
| yogi, booboo, grizzly, rupert, baloo, teddy, bungle, care now write code to alter the array: | |
| a) Change 'baloo' to 'greppy' b) Add 'fozzie' to the end of the array c) Print the resulting array, and its length |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
