Learning Perl

Learning PerlSearch this book
Previous: 15.5 TransliterationChapter 15
Other Data Transformation
Next: 16. System Database Access
 

15.6 Exercises

See Appendix A, Exercise Answers for answers.

  1. Write a program to read a list of filenames, breaking each name into its head and tail components. (Everything up to the last slash is the head, and everything after the last slash is the tail. If there's no slash, it's all in the tail.) Try this with things like /fred, barney, and fred/barney. Do the results make sense?

  2. Write a program to read in a list of numbers on separate lines, and sort them numerically, printing out the resulting list in a right-justified column. (Hint: the format to print a right-justified column is something like %20g.)

  3. Write a program to print the real names and login names of the users in the /etc/passwd file, sorted by the last name of each user. Does your solution work if two people have the same last name?

  4. Create a file that consists of sentences, one per line. Write a program that makes the first character of each sentence uppercase and the rest of the sentence lowercase. (Does it work even when the first character is not a letter? How would you do this if the sentences were not already one per line?)


Previous: 15.5 TransliterationLearning PerlNext: 16. System Database Access
15.5 TransliterationBook Index16. System Database Access



Banner.Novgorod.Ru