home *** CD-ROM | disk | FTP | other *** search
- 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
-
- 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."
-