in reply to Re: Reading from a file
in thread Reading from a file

roboticus,
Thanks, but as I've shown in my 1st posting, what I'm doing now, is to read the file into an array and then I can read from the array line-by-line, I don't see how your sugestion is different.
The main problem is that I read this file a lot(I actually have various reporter files), and I need to find a specific line ( the "header" ) and the last line(the updated "data" )
my question is: is there a simple way to do so, and is there a way to do so without "saving" the whole file into an array or string or such.
Thanks

Replies are listed 'Best First'.
Re^3: Reading from a file
by dsheroh (Monsignor) on May 23, 2006 at 14:31 UTC
    Sounds to me like Joost had the right idea: Try File::Tail. That would allow you to read the whole file in at startup, scan it for the last header line, and then just pick up the new lines (data or header) as they're added instead of repeatedly reading and processing the entire file.
Re^3: Reading from a file
by roboticus (Chancellor) on May 23, 2006 at 23:24 UTC
    just dave:

    I was thinking that by using a single string rather than an array, you can avoid the explicit looping, making your code clearer. Since you also mentioned having a memory leak, I thought that a single string would fragment memory much less than a bazillion smaller strings. That might make it easier for perl to reuse the memory and/or recognize what can be freed

    Other than that, it's not much different at all.

    Of course, since you're rereading the same file repeatedly, I think that Joost's suggestion is my favorite so far. Then, while looking up File::Tail, I saw File::Tail::App, which is pretty cool because it does much of the grunt work for you.

    --roboticus