Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

I. Exercises > 5. Input and Output

Chapter 5. Input and Output

5.1. Write a program to read lines from all of the files on the command line and print out each line prefaced with its filename. (Answer to Exercise 5.1)

5.2. Modify your answer for Exercise 5.1 so after it reads lines from the files you specify on the command line, it reads in lines from standard input and prefaces the line with stdin. (Answer to Exercise 5.2)

5.3. Explain the output of this program then fix the bug. The line with while comes straight from the perlfaq4 documentation. You can see the whole answer about adding commas to numbers using perldoc –q comma:

#!/usr/bin/perl
use strict;
use warnings;
 
print format_number( 9999 ), "\n";

sub format_number {
    local $_ = shift;

    1 while s/^([-+]?\d+)(\d{3})/$1,$2/;

    print $_;
    }

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial