citycrew has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am using following tie process to load large files into an array. Some of the files will be over a gig so I don't want any mem usage at all. I want to confirm that referencing $ra_list->[0] will not recreate the list into memory at all. I know that it won't on a standard array ref but this is a tie::file and I don't know if they work differently in that respect.

my $ra_list = getList(); my $line1 = $ra_list->[0]; sub getList { my @list; tie(@list, 'Tie::File', '/path/file', memory => 0, mode => O_RDONLY) +; return \@list; }

Replies are listed 'Best First'.
Re: Referencing a Tie::File Array
by ikegami (Patriarch) on Oct 01, 2011 at 01:21 UTC
    $ra_list->[0] is the same as $list[0]. I'm not sure what you are asking, but if $list[0] doesn't do it, neither does $ra_list->[0]. Does that answer your question?
      Thanks ikegami, I just wanted to confirm that when I use '$ra_list = getList()' it doesn't copy the data from 'return \@list' into memory at all, and it keeps the reference to that tie::file intact. I realize they are the same with a normal array, but tie::file is a different beast.
        Both returning the value and the assignment copy the value, but the value being returned is a reference, and that's a cheap operation.