in reply to tail -1 emulation efficiency
Rather than seeking to the end and then reading backwards a byte at a time, it might be quicker to read a reasonable (greater than line length) sized chunk from the end of the file and then let the regex engine locate the last line.
#! perl -slw use strict; our $MAX ||= 512; open TAIL, '< :raw', $ARGV[ 0 ] or die "$ARGV[ 0 ] : $!"; sysseek( TAIL, -$MAX, 2 ); sysread( TAIL, my $buffer, $MAX ); my( $line ) = $buffer =~ m[\n(.*?$)]; print $line;
|
|---|