Learning Perl

Learning PerlSearch this book
Previous: 14.6 Sending and Receiving SignalsChapter 14
Process Management
Next: 15. Other Data Transformation
 

14.7 Exercises

See Appendix A, Exercise Answers for answers.

  1. Write a program to parse the output of the date command to get the current day of the week. If the day of the week is a weekday, print get to work, otherwise print go play.

  2. Write a program that gets all of the real names of the users from the /etc/passwd file, then transforms the output of the who command, replacing the login name (the first column) with the real name. (Hint: create a hash where the key is the login name and the value is the real name.) Try this both with the who command in backquotes and opened as a pipe. Which was easier?

  3. Modify the previous program so that the output automatically goes to the printer. (If you can't access a printer, perhaps you can send yourself mail.)

  4. Suppose the mkdir function were broken. Write a subroutine that doesn't use mkdir, but invokes /bin/mkdir with system instead. (Be sure that it works with directories that have a space in the name.)

  5. Extend the routine from the previous exercise to employ chmod to set the permissions.


Previous: 14.6 Sending and Receiving SignalsLearning PerlNext: 15. Other Data Transformation
14.6 Sending and Receiving SignalsBook Index15. Other Data Transformation