On 3/16/07, Jeff Pang <[EMAIL PROTECTED]> wrote:
snip
@tmp =  map { (split)[2] } grep { /localhost/ } <FILE>;
snip

This is a bad idea if the file you are reading from is at all large.
It is better to use a real loop rather than map or grep when reading
from a file.  The problem lies in the fact that all of the lines are
read into memory before grep gets called.  Watch your memory usage
while you run the second two commands.

perl -e 'print "x" x 80, "\n" for 0 .. 10_000_000' > big
perl -e 'while (<>) { print if /y/ }' big
perl -e 'print grep { /y/ } <>' big

This should be written like this:

while (<FILE>) {
  next unless /localhost/;
  push @tmp, (split)[2];
}

You should also be using strict and warnings if you are going to write
that much code, but you could always just say

perl -ane 'if (/localhost/) { print "$F[2]\n"; last }'  $INPUTDB/postgresql.conf

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to