filter.pl

Download filter.pl

 1: #!/usr/bin/perl -TW
 2: #
 3: # filter.pl - This demo perl program shows how to read a filename
 4: # from the command line, open the file for reading, do something
 5: # to it (convert to all uppercase), and send the results to stdout.
 6: # As an extra, notice how if no filename is supplied then STDIN
 7: # is used instead.
 8: #
 9: # Written 3/2007 by Wayne Pollock, Tampa Florida USA
10: 
11: if ( @ARGV )
12: {  $filename = $ARGV[0];
13: } else {
14:    $filename = "-";
15: }
16: 
17: open( FILE, "< $filename" ) or die "$filename: $!";
18: 
19: $filename = "STDIN" if ( $filename eq "-" );
20: 
21: print "filename: $filename\n";
22: 
23: while ( <FILE> )
24: {
25:    tr/a-z/A-Z/;
26:    print;
27: }
28: 
29: print "The end.\n";
30: 
31: close( FILE );