The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Array::FileReader - Lazily tie files to arrays for reading

SYNOPSIS

  use Array::FileReader;
  tie @foo, Array::FileReader, "some.file";
  print $foo[30];

DESCRIPTION

Plenty of times I've wanted to run up and down a file like this:

    @foo = <FILE>;
    for (0..100) {
        print $foo[$_];
    }
    print $foo[10], $foo[20], $foo[30];

Of course, this is hugely inefficient since you have to load the entire file into an array in memory. Array::FileReader removes the inefficiency by only storing the line offsets in memory, and only discovering the line offsets when a line is called for. For instance, $foo[4] will only load 4 numbers into memory, and then $foo[30] will load another 26.

Because the file offsets are discovered when needed, there's no good way of getting the size of the file - you just have to pad through them all, which is slow.

The module was designed to speed up Mark-Jason Dominus' Algorithm::Diff module when finding differences between two very large files. In fact, it makes things less efficient, since the first thing that module does is find the size of the arrays. It just goes to show, doesn't it?

MAINTAINER

Curtis "Ovid" Poe, <1napc-pmetsuilbup@yahoo.com>

Reverse the name to email me.

AUTHOR

Simon Cozens, <simon@cpan.org>

SEE ALSO

Algorithm::Diff, Tie::MmapArray