Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: The joys of bad code by Random_Walk
in thread The joys of bad code by BUU

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2018-03-24 18:48 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (299 votes). Check out past polls.