in reply to Large text files into arrays, accessing final elements

if @myfile is tied file array: (...) $size=@myfile; #this dies and gives "out of memory" error

This issue seems to be directly addressed in the docs to Tie::File (in the caveats):

Note that accessing the length of the array via $x = scalar @tied_file accesses all records and stores their offsets.

Did you try, for example:

print $myfile[-1];

Replies are listed 'Best First'.
Re^2: Large text files into arrays, accessing final elements
by BrowserUk (Patriarch) on Feb 07, 2010 at 19:55 UTC
    Did you try, for example: print $myfile[-1];

    That will suffer exactly the same problems. There is simply no way to know how many lines a file (with variable length lines) contains without reading the whole file.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.