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

13.8. Exercises

See Appendix A for answers.

  1. Write a program that works like rm, deleting the files given as command-line arguments when the program is invoked. (You don't need to handle any options of rm.)

    Be careful to test this program in a mostly empty directory so you don't accidentally delete useful stuff! Remember that the command-line arguments are available in the @ARGV array when the program starts.

  2. Write a program that works like mv, renaming the first command-line argument to the second command-line argument. (You don't need to handle any options of mv, or more than two arguments.) You may wish to consider how to handle the rename when the destination is a directory.

  3. Write a program that works like ln, creating a hard link from the first command-line argument to the second. (You don't need to handle any options of ln, or more than two arguments.)

  4. If you have symlinks, modify the program from the previous exercise to handle an optional -s switch.

  5. If you have symlinks, write a program that looks for all symlinked files in the current directory and prints out their name and symlinked value similar to the way ls -l does it (name -> value). Create some symlinks in the current directory and test it out.

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