O'Reilly logo

Learning Perl, Second Edition by Randal L. Schwartz, Tom Christiansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.7. Exercises

See Appendix A 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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required