Re: oneliner to delete last line of file

2002-11-29 Thread John W. Krahn
Ramprasad A Padmanabhan wrote: > > Hello all Hello, > I am using redhat linux 7.2 > > I am required to delete the last line of a file. Now I am doing a > cumbersome thing like this > > perl -e '@_=<>;pop @_;print @_;' $FILE > $FILE.tmp > mv $FILE.tmpl $FILE > > Cant I do it any better Here i

Re: oneliner to delete last line of file

2002-11-29 Thread Sudarshan Raghavan
On Fri, 29 Nov 2002, Ramprasad A Padmanabhan wrote: > > Hello all > > I am using redhat linux 7.2 > > I am required to delete the last line of a file. Now I am doing a > cumbersome thing like this > > perl -e '@_=<>;pop @_;print @_;' $FILE > $FILE.tmp > mv $FILE.tmpl $FILE > > Cant I do it an

oneliner to delete last line of file

2002-11-29 Thread Ramprasad A Padmanabhan
Hello all I am using redhat linux 7.2 I am required to delete the last line of a file. Now I am doing a cumbersome thing like this perl -e '@_=<>;pop @_;print @_;' $FILE > $FILE.tmp mv $FILE.tmpl $FILE Cant I do it any better -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional comman

Re: Last line of file...

2001-12-18 Thread Michael R. Wolf
"James Kelty" <[EMAIL PROTECTED]> writes: > Well, I thought of that earlier, but I also thought that I > was not guaranteed that the order of an array was > unreliable, so I may not actually be getting the 'last' of > the file. True or untrue ? By definition: Arrays are ordered. Diamond

Re: Last line of file...

2001-12-18 Thread John W. Krahn
James Kelty wrote: > > 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() { >do somethin

RE: Last line of file...

2001-12-18 Thread Peter Cornelius
If you know the size of the last line you can use 'seek' to get there, but this operates on bytes, not chars. If the records are of a fixed size this would be the most efficient way to do it. use POSIX; #This gives us the SEEK_END constant seek (FH, -$recsize, SEEK_END) or die "Could not seek: $

RE: Last line of file...

2001-12-18 Thread Peter Cornelius
You are probably thinking of associative arrays. They are declared with the '%' character in the lead and do not have any intelligible order. With a normal array the order is guaranteed. If your files aren't to big I've found this idiom useful when I just want the last line. open (FH, "smallfi

Re: Last line of file...

2001-12-18 Thread Michael Fowler
On Tue, Dec 18, 2001 at 10:43:54AM -0800, James Kelty wrote: > Well, I thought of that earlier, but I also thought that I was not > guaranteed that the order of an array was unreliable, so I may not actually > be getting the 'last' of the file. True or untrue ? Arrays are ordered, they must be, t

Re: Last line of file...

2001-12-18 Thread Agustin Rivera
; Cc: "James Kelty" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Tuesday, December 18, 2001 11:02 AM Subject: Re: Last line of file... > 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

Re: Last line of file...

2001-12-18 Thread Etienne Marcotte
uot; <[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 co

RE: Last line of file...

2001-12-18 Thread James Kelty
Ok, thanks! -James -Original Message- From: Agustin Rivera [mailto:[EMAIL PROTECTED]] Sent: Tuesday, December 18, 2001 10:49 AM To: James Kelty; [EMAIL PROTECTED] Subject: Re: Last line of file... I've never had an instance where that didn't work. I use for $a(0..$#array

Re: Last line of file...

2001-12-18 Thread smoot
> "McCollum, Frank" <[EMAIL PROTECTED]> said: > I'm a beginner too, given, but alternatively, you could unshift the lines > into an array and just check the last variable. This would allow you to > reference the other lines later if there was more work to be done here. Something like this while

Re: Last line of file...

2001-12-18 Thread Agustin Rivera
a" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Tuesday, December 18, 2001 10:43 AM Subject: RE: Last line of file... > Well, I thought of that earlier, but I also thought that I was not > guaranteed that the order of an array was unreliable, so I may not actual

RE: Last line of file...

2001-12-18 Thread James Kelty
t: Tuesday, December 18, 2001 10:44 AM To: James Kelty; [EMAIL PROTECTED] Subject: Re: Last line of file... In that case, do this.. open(IN, "filename"); @file=; print "$file[$#file]\n"; Agustin Rivera Webmaster, Pollstar.com http://www.pollstar.com - Original Message ---

Re: Last line of file...

2001-12-18 Thread Agustin Rivera
ROTECTED]> 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- >

RE: Last line of file...

2001-12-18 Thread McCollum, Frank
Sent: Tuesday, December 18, 2001 1:22 PM To: [EMAIL PROTECTED] 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, "$fi

Re: Last line of file...

2001-12-18 Thread Agustin Rivera
mber 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&q

Last line of file...

2001-12-18 Thread James Kelty
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() { do something with the line; } close(FILE); What I w