Is tying over 5 hashes on a single page considered a waste of memory? If I try to tye..20 databases at a time would that, generally speaking, have a big increase on load time?

What is a "page"? Perl doesn't have any concept of "pages", so your question is a bit strange. If you mean whether tying 5 hashes in a single program is considered a waste of memory, it all depends what your program does. If your program calculates the first 100 prime numbers, even tying a single hash is probably a waste. If your program does a tax audit for all people in the US, it might not be a waste.

As for "tying to 20 databases" (do you mean connecting?) it will certainly take some time. But whether that's a big increase depends on the rest of the program, doesn't? Consider your databases are heavily loaded, and on average it takes a second to connect to a single database. That 20 seconds. If your program runs for a week, the 20 seconds don't matter. If your program is run every 10 seconds, the 20 seconds do matter.

The problem with your questions is that they can't be answered without knowing a lot more about the specific program.

Would it use a lot of memory if I used an automated script to parse the text of a url every 5 minutes?

That depends on what you find a lot, how much text there is to parse, how you parse it, and what you are doing with the results. The best way to get an answer is to write the program and test it.

Is it faster to do a foreach ( keys %hash) { $cnt++ or storing the hash into an array to count key/value pairs?

That's probably the wrong question to ask. It all depends on what your purpose is of storing the data. If all you care about is "how many", both a hash and an array are silly. If you want to do something else, than that something else decides whether a hash or an array is the most useful. Both scalar keys %hash and scalar @array are constant time operations.

What are some common areas or traps that would increase memory wastage?

The first is: using Perl itself. Once you have committed yourself to use Perl, you are going to use a lot of memory. If you are in a situation where the memory usage of as few as 5 tied hashes are a valid concern, you shouldn't have used Perl in the first place.

Use C. That seems to be ideal for you - there you have lots of control over the memory usage.

Abigail


In reply to Re: Memory /speed questions by Abigail-II
in thread Memory /speed questions by sulfericacid

Title:
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, details, 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, summary, 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.