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

  1. # Perl version of Head.
  2. # Usage : head [-#] file1 file2 ...
  3. #
  4.  
  5. # Is the first argument a -# ?
  6. if (substr($ARGV[0], 0, 1) eq "-")
  7. {
  8.     # Yes, so read it.
  9.     $lines = -(shift);
  10. }
  11. else
  12. {
  13.     # No, so default to ten lines.
  14.     $lines = 10;
  15. }
  16.  
  17. # For each file specified.
  18. foreach (<@ARGV>)
  19. {
  20.     # Print the filename.
  21.     print "\n--- ".$_." ---\n\n";
  22.     
  23.     # Print the first few lines of the file.
  24.     open($input, $_);
  25.     for ($i=0; $i<$lines; ++$i)
  26.     {
  27.         # If not past the eof.
  28.         if ($line = <$input>)
  29.         {
  30.             print $line;
  31.         }
  32.         else
  33.         {
  34.             $i = $lines;
  35.         }
  36.     }
  37.     close($input);
  38. }
  39.