Re: perl head and tail command ?



Rob Dixon wrote:
Richard Lee wrote:
when you are doing it to filehandle vs array, which consumes more memory?

my source file is about 100,000 lines...

open my $source, 'tmp/server.txt' or die !$;

VS tie my @file, 'Tie::File', '/tmp/server.txt' or die $!;

Neither of them use any significant memory until you start reading from the file. Unless you mess about with file positioning with seek() and tell(). the only way to retrieve the last record in a file using a standard file handle is to read all the way through it one line at a time. The documentation for Tie::File says this:

The file is *not* loaded into memory, so this will work even for gigantic files.

So it is likely to be best for your needs.

Actually, Tie::File seems to be very slow.

http://www.mail-archive.com/beginners%40perl.org/msg93566.html

However, you should not worry about speed or memory usage until you have written the clearest program you can and then find that it consumes too many resources.

True.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Re: perl head and tail command ?
    ... Rob Dixon wrote: ... I asked this because I have a filehandle which was, ... my source file is about 100,000 lines... ... open my $source, 'tmp/server.txt' or die!$; ...
    (perl.beginners)
  • Re: DIV verschieben
    ... > Source File: http://www.76impressions.org/76.js ... > Source Code: ... ich hab auch das 76.js mal rausgenommen. ... Jetzt is nur noch die ...
    (de.comp.lang.javascript)
  • Re: 2.6.0-test4-mm1: wl3501_cs.c doesnt compile
    ... I see, I'll fix this one, I had a problem with this in another source file, ... Die, gcc 2.95 die! ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)