Exercises

15.5 Exercises

See Section A.14 for answers to the following exercises:

1.       [10] Write a program to read in a list of numbers and sort them numerically, printing out the resulting list in a right-justified column. Try it out on this sample data, or use the file numbers, from the O'Reilly web site (see the Preface):

17 1000 04 1.50 3.14159 -10 1.5 4 2001 90210 666

2.       [15] Make a program that will print the following hash's data sorted in case-insensitive alphabetical order by last name. When the last names are the same, sort those by first name (again, without regard for case). That is, the first name in the output should be Fred's, while the last one should be Betty's. All of the people with the same family name should be grouped together. Don't alter the data. The names should be printed with the same capitalization as shown here. (You can find the source code to create a hash like this in the file sortable_hash with the other downloaded files.)

3.          my %last_name = qw{ 
4.           fred flintstone Wilma Flintstone Barney Rubble
5.           betty rubble Bamm-Bamm Rubble PEBBLES FLINTSTONE
}; 

6.       [15] Make a program that looks through a given string for every occurrence of a given substring, printing out the positions where the substring is found. For example, given the input string "This is a test." and the substring "is", it should report positions 2 and 5. If the substring were "a", it should report 8. What does it report if the substring is "t"?

 



Learning Perl
Learning Perl, 5th Edition
ISBN: 0596520107
EAN: 2147483647
Year: 2001
Pages: 205

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net