GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Array::FileReader(3) User Contributed Perl Documentation Array::FileReader(3)

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

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

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?

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

Reverse the name to email me.

Simon Cozens, <simon@cpan.org>

Algorithm::Diff, Tie::MmapArray
2005-10-07 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.