in reply to Unix 'head' in perl

Many ways you can do this. Here's one:

use strict; use warnings; my $file = shift; print head($file); sub head { my ($file,$count) = @_; $count ||= 10; open FILE, '<', $file or die "Cannot open ($file) for reading: $!"; my @data; while (defined (my $line = <FILE>)) { push @data => $line; last if $. >= $count; } close FILE or die "Cannot close ($file): $!"; return @data; }

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)