my $lastline = do {
open my $pipe, '-|', tail => -1, $file
or die "Can't spawn tail: $!\n";
<$pipe>;
};
print $lastline;
I'm not sure why you chose to write your loop that way, either. Why the obfuscatory infinite loop with an abort condition as in this?
while( 1 ) {
my $file = shift || last;
# ...
}
It took me a moment to realize that you meant something entirely different than what I assumed at first glance. The natural thing would have been to put the abort condition where you normally put it: in the loop condition.
while( @ARGV ) {
my $file = shift;
# ...
}
Of course, that's clearer written as
for my $file ( @ARGV ) {
# ...
}
So we get
for my $file ( @ARGV ) {
my $lastline = do {
open my $pipe, '-|', tail => -1, $file
or die "Can't spawn tail: $!\n";
<$pipe>;
};
print $lastline;
}
I find that significantly clearer despite the changes not changing any of the semantics.
Makeshifts last the longest.
|