in reply to Super Duper Inefficient
here's a clue:
foreach $server (@servers) { chomp $server; open TMP, ">/tmp/$server.tmp"; $ENV{"FILENAME"} = "/tmp/$server\.tmp"; foreach(@DATA) { ($hostid, $time, $get, $post, $currconn) = split(/\t/); next if ($hostid ne $SERVER{$server}); ## more here... } close TMP; }
this is the inefficiency. invert these loops to make this something like:
## iterate through record foreach(@DATA) { ($hostid, $time, $get, $post, $currconn) = split(/\t/); ## match against the server list and process accordingly foreach $server (@servers) { chomp $server; next unless $hostid eq $SERVER{$server}; open TMP, ">>/tmp/$server.tmp"; $ENV{"FILENAME"} = "/tmp/$server\.tmp"; ## more here... close TMP; ## done with this record, move on last; } }
then you'll iterate over the data once, writing to multiple files depending on the $hostid variable. after each data record is processed, it moves on to the next line without evaluating any other servers in the list.
if you haven't already, you might consider using warnings or -w. you might also consider using strict. it would take some work with this code, but it makes perl debugging so much easier.
~Particle *accelerates*
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Super Duper Inefficient
by Earindil (Beadle) on Jun 20, 2003 at 13:19 UTC | |
by particle (Vicar) on Jun 20, 2003 at 13:26 UTC |