Section 14.8. Exercises

14.8. Exercises

See Appendix A for answers to the following exercises:

  1. [6] Write a program that changes to some particular (hardcoded) directory, like the system's root directory, and executes the ls -l command to get a long-format directory listing in that directory. (If you use a non-Unix system, use your own system's command to get a detailed directory listing.)

  2. [10] Modify the previous program to send the output of the command to a file called ls.out in the current directory. The error output should go to a file called ls.err. (You don't need to do anything special about the fact that either of these files may end up being empty.)

  3. [8] Write a program to parse the output of the date command to determine the current day of the week. If the day of the week is a weekday, print get to work; otherwise, print go play. The output of the date command begins with Mon on a Monday.[*] If you don't have a date command on your non-Unix system, make a fake program that prints a string similar to one that date might print. We'll give you this two-line program if you promise not to ask us how it works:

    [*] At least when the days of the week are being given in English. You might have to adjust accordingly if that's not the case on your system.

         #!/usr/bin/perl     print localtime(  ) . "\n"; 

Learning Perl
Learning Perl, 5th Edition
ISBN: 0596520107
EAN: 2147483647
Year: 2003
Pages: 232

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: