Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: The joys of bad code

by Random_Walk (Prior)
on Nov 16, 2004 at 15:33 UTC ( [id://408136]=note: print w/replies, xml ) Need Help??


in reply to The joys of bad code

I worked with a perl coder once who wrote something like this

#!/usr/bin/perl -w `cd test_dir` `gunzip test_script.tar.gz` `tar -xvf test_script.tar` #you are getting the idea now

I asked him why he did not just write a shell script, his answer with no note of irony was that he did not know shell !

The following was causing serious memmory hogage in a production environment, multiple instances (30+) were running at any time, each took about 4 seconds to complete and eat a big chunck of RAM.

# we enter here with a hostname $host and must look it up # in a file containing details for >100K hosts open FH, $hosts_file or die "something appropriate\n"; while (<FH>) { ($a,$b,$c,$d)=split $_, /\t/, 4; # first entry in each line is hostname # $b is the data we need for the host $hash{$a}=$b; } if (exists $hash{$host}) { return $hash{$host} } else { return error } # needles to say %hash was global, well everything was # and %hash used again

after the obvious changes it reduced to running in around 0.3 seconds, with a tweak to sort the hosts_file file when it was generated (once per day) and binary search it it was down to <0.04 secs per run

Cheers,
R.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://408136]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-03-19 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found