If the file is huge I wouldn't recommend doing so.. because it puts all the file into your array
I think you can go directly to the last line if you know exactly the length of the last line, am I wrong on this one? Like seeking to the end and reading backwards of n chars? Etienne Agustin Rivera wrote: > > In that case, do this.. > > open(IN, "filename"); > @file=<IN>; > print "$file[$#file]\n"; > > Agustin Rivera > Webmaster, Pollstar.com > http://www.pollstar.com > > ----- Original Message ----- > From: "James Kelty" <[EMAIL PROTECTED]> > To: "Agustin Rivera" <[EMAIL PROTECTED]> > Sent: Tuesday, December 18, 2001 10:27 AM > Subject: RE: Last line of file... > > > Thank you, but I would like to programmatically do it from perl rather > than > > using shell commands. Make the whole script more portable. > > > > -James > > > > > > -----Original Message----- > > From: Agustin Rivera [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, December 18, 2001 10:30 AM > > To: James Kelty; [EMAIL PROTECTED] > > Subject: Re: Last line of file... > > > > > > If this is all you want your script to do, I suggest using this command > > > > tail -n1 filename > > > > Agustin Rivera > > Webmaster, Pollstar.com > > http://www.pollstar.com > > > > > > > > ----- Original Message ----- > > From: "James Kelty" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Tuesday, December 18, 2001 10:21 AM > > Subject: Last line of file... > > > > > > > Is there a document in perldoc that tells the best way to get the last > > line > > > of a file? Below is my usual code for reading a file. > > > > > > > > > #!/usr/bin/perl -w > > > > > > $file = qq(/some/file/); > > > > > > open FILE, "$file" or die "Cannot open file: $!\n"; > > > > > > while(<FILE>) { > > > do something with the line; > > > } > > > > > > close(FILE); > > > > > > > > > What I want to do is read just the last line. Might help in the case of > a > > > password file or something like that. > > > > > > Thanks! > > > > > > -James > > > > > > > > > > > > > > > -- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- Etienne Marcotte Specifications Management - Quality Control Imperial Tobacco Ltd. - Montreal (Qc) Canada 514.932.6161 x.4001 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]