Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: The joys of bad code

by Random_Walk (Prior)
on Nov 16, 2004 at 15:33 UTC ( #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


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://408136]
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-02-20 10:08 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (268 votes). Check out past polls.