alex chen wrote: > hi, all > > i want to know how to get the last line of > a file .i know the func read has a paramenter offset but i don't know how to > use it.please help!!!
the easy way (but inefficient): # read until the last line open F, "file.txt" or die $!; $last=$_ while <F>; the more (though probably not the *most*) efficient way: # position pointer at the end of file, and then search for newlines open F, "file.txt" or die $!; seek F, 0, 2; while ($pos = tell F) { seek F, -($pos > 1024 ? 1024 : $pos), 1 or die; read F, $block, 1024; $_ .= $block; do {$last=$1; print ">>$last"; last} if /.+\n(.+)/s; } print "Last line is: $last"; hope it helps. -- dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]