home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3334 < prev    next >
Encoding:
Internet Message Format  |  1991-05-17  |  951 b 

  1. From: tchrist@convex.COM (Tom Christiansen)
  2. Newsgroups: comp.lang.perl,alt.sources
  3. Subject: better head
  4. Message-ID: <1991May16.152356.3186@convex.com>
  5. Date: 16 May 91 15:23:56 GMT
  6.  
  7. Here's a little head clone I once wrote out of frustration 
  8. with head's misbehaving on files with long lines.  
  9.  
  10.  
  11.     #!/usr/bin/perl
  12.     #
  13.     # head -- perl clone of head command, but without heads silly 
  14.     #      limits regarding line lengths.  runs faster than 
  15.     #      C version, too!   tchrist@convex.com
  16.  
  17.     $num = ($ARGV[0] =~ /^-(.+)/ && shift) ? $1 : 10; 
  18.     die "$0: badly formed number: $1\n" unless $num =~ /^\d+$/;
  19.  
  20.     unshift(@ARGV, '-') unless $argc = @ARGV;  # <> changes @ARGV
  21.     while (<>) {
  22.     if ($. == 1 && $argc > 1) {
  23.         print "\n" if $deja_imprime++;
  24.         print "=> $ARGV <=\n" ;
  25.     }
  26.     if ($. <= $num) {
  27.         print;
  28.     } else {
  29.         close ARGV;
  30.     } 
  31.     } 
  32. --
  33. Tom Christiansen        tchrist@convex.com    convex!tchrist
  34.         "So much mail, so little time." 
  35.