better head

Tom Christiansen tchrist at convex.COM
Fri May 17 01:23:56 AEST 1991


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 at 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 at convex.com	convex!tchrist
		"So much mail, so little time." 



More information about the Alt.sources mailing list