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
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
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
"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
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
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: $
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
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
;
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
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
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
> "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
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
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 ---
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-
>
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
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
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
18 matches
Mail list logo