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, "smallfile") or die "Couldn't open smallfile";
($last_line) = reverse <FH>;
close (FH);

I believe this reads the entire file into memory so you wouldn't want to do
it with very large files.

Take a look at perldoc -f reverse for more info.

Hope this helps,
Peter C.

-----Original Message-----

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 ?

----- Really Original Message-----


In that case, do this..

open(IN, "filename");
@file=<IN>;
print "$file[$#file]\n";

----- Really Really Original Message -----

> Thank you, but I would like to programmatically do it from perl rather
than
> using shell commands. Make the whole script more portable.
>
> -James
>
>
> -----Really Really Original Message-----
>
> If this is all you want your script to do, I suggest using this command
>
> tail -n1 filename
>
>
> ----- Original Message -----
> > 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]

Reply via email to