home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixcmds_1 / BIN / cat < prev    next >
Encoding:
Text File  |  1993-06-10  |  392 b   |  30 lines

  1. # Perl version of cat
  2. # Usage : cat [-n] file1 file2 ...
  3. #
  4.  
  5. $number = 0;
  6. # Is the first argument a -n ?
  7. if (substr($ARGV[0], 0, 2) eq "-n")
  8. {
  9.     $number = 1;
  10.     shift;
  11. }
  12.  
  13. # For each file specified.
  14. foreach $_ (<@ARGV>)
  15. {
  16.     open(INPUT, $_);
  17.  
  18.     $count = 1;
  19.     while ($line = <INPUT>)
  20.     {
  21.         $line =~ s/    /    /g;
  22.         if ($number == 1)
  23.         {
  24.             printf("%4d ", $count++);
  25.         }
  26.         print $line;
  27.     }
  28.     close(INPUT);
  29. }
  30.