Date: 29 Jun 2001 06:13:12 GMT From: damian@qimr.edu.au (Damian James) Subject: Re: pull out last line in a text file Message-Id: Logan Shaw chose 28 Jun 2001 20:09:04 -0500 to say this: >In article <9hgjl1$kqs$1@charity.cs.utexas.edu>, >Logan Shaw wrote: >>In article <9hgfbe01ehm@drn.newsguy.com>, >>Patrick Flaherty wrote: >>>How, in Perl, do I pull out the last line (or lines plural as in tail) of a text >>>file? >> >>Here's the quick and dirty way: > >Oops, I forgot to give the obfuscated version: > > print @{[<>]}[-3 .. -1]; > A way to do this without reading the *whole* file into RAM: my @lines = ('') x 3; shift @lines, push(@lines, $_) while <>; print @lines; Cheers, Damian -- @:=grep!($;+=m!$/|#!),split//,;@;=0..$#:;while(@;){for($;=@;;--$;;) {@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select $,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__ Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...