Learning Perl on Win32 Systems

Learning Perl on Win32 SystemsSearch this book
Previous: 6.3 Output to STDOUTChapter 6
Basic I/O
Next: 7. Regular Expressions
 

6.4 Exercises

See Appendix A, Exercise Answers for answers.

  1. Write a program that acts like type, but reverses the order of the lines from the files specified on the command line, or all the lines from standard input if no files are specified.

  2. Modify the program from the previous exercise so that each file specified on the command line has its lines individually reversed. (Yes, you can do this with only what's been shown to you so far, even excluding the stroll in Chapter 1, Introduction.)

  3. Write a program that reads a list of strings on separate lines, and prints the strings in a right-justified 20-character column. For example, inputting hello, good-bye prints hello and good-bye, right-justified in a 20-character column. (Be sure your program is actually using a 20-character column, and not a 21-character column. That mistake is common.)

  4. Modify the program from the previous exercise to allow the user to select the column width. For example, entering 20, hello, and good-bye should do the same thing as the previous program did; but, entering 30, hello, and good-bye should justify hello and good-bye in a 30-character column.


Previous: 6.3 Output to STDOUTLearning Perl on Win32 SystemsNext: 7. Regular Expressions
6.3 Output to STDOUTBook Index7. Regular Expressions