Skip to content

Instantly share code, notes, and snippets.

@lukecameron
Created August 18, 2012 07:28
Show Gist options
  • Save lukecameron/3385037 to your computer and use it in GitHub Desktop.
Save lukecameron/3385037 to your computer and use it in GitHub Desktop.
comp2041: perl implementation of tail
#!/usr/bin/perl -w
$n = -10;
@files = ();
foreach $arg (@ARGV) {
if ($arg =~ /^(-\d+)$/) {
$n = $1;
} else {
push @files, $arg;
}
}
push @files, "-" unless @files; #added after due date
foreach $f (@files) {
open(F,"<$f") or print "$0: Can't open $f\n" and next;
# process F
@hello = <F>;
print ">>> $f <<<\n" if @files > 1; #added if statement after due date
if (@hello + $n < 1) {
print @hello;
} else {
print @hello[$n..-1];
}
close(F);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment