Craig Cardimon <> wrote: > I'm trying to use the Tie::File module to access large text files. > The test file I'm working on now is about 42MB. > > According to the instructions at > http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/lib/Tie/File.html, > > "Tie::File represents a regular text file as a Perl array. Each > element in the array corresponds to a record in the file. The first > line of the file is element 0 of the array; the second line is > element 1, and so on." > > and... > > "The file is not loaded into memory, so this will work even for > gigantic files." > > Sounds perfect. That's just what I need. > > However, there appears to be a caveat in that this module can run > very slowly while it is binding itself to a file. > > I don't understand that. If the file is not being loaded into memory, > what's the holdup? > > Anyway, all I'm trying to do right now is get a reading on how many > lines (records) there are in my test file, but the script simply > grinds and grinds. > > My somewhat abbreviated code: > > use Tie::File; > use Fcntl 'O_RDONLY'; > > tie ( @lines, "Tie::File", "$testfile", mode => O_RDONLY ) or die > "\nUnable to Tie File >$testfile< \n" ; > > my $n_recs = @lines; > > print "\n\tThere are $n_recs records or lines are in the file\n";
Caveat is the right word. This is from the CAVEATS section of 'perldoc Tie::File'. "Note that accessing the length of the array via $x = scalar @tied_file accesses all records and stores their offsets." So you have probably just asket it to read through the whole file to store the offsets of every line, which might take a little while for a large file. HTH -- Brian Raven ================================= Atos Euronext Market Solutions Disclaimer ================================= The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of Atos Euronext Market Solutions. L'information contenue dans cet e-mail est confidentielle et uniquement destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail vous parvient par erreur, nous vous prions de bien vouloir prevenir l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre systeme. Le contenu de ce message electronique ne represente pas necessairement la position ou le point de vue d'Atos Euronext Market Solutions. _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
