Xref: utzoo comp.lang.perl:5335 alt.sources:3743 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!spool.mu.edu!uunet!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl,alt.sources Subject: better head Message-ID: <1991May16.152356.3186@convex.com> Date: 16 May 91 15:23:56 GMT Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Followup-To: comp.lang.perl Organization: CONVEX Software Development, Richardson, TX Lines: 28 Nntp-Posting-Host: pixel.convex.com Here's a little head clone I once wrote out of frustration with head's misbehaving on files with long lines. #!/usr/bin/perl # # head -- perl clone of head command, but without heads silly # limits regarding line lengths. runs faster than # C version, too! tchrist@convex.com $num = ($ARGV[0] =~ /^-(.+)/ && shift) ? $1 : 10; die "$0: badly formed number: $1\n" unless $num =~ /^\d+$/; unshift(@ARGV, '-') unless $argc = @ARGV; # <> changes @ARGV while (<>) { if ($. == 1 && $argc > 1) { print "\n" if $deja_imprime++; print "=> $ARGV <=\n" ; } if ($. <= $num) { print; } else { close ARGV; } } -- Tom Christiansen tchrist@convex.com convex!tchrist "So much mail, so little time."