*Considers getting -- on this post...ah..*

OK. I don't know why this post strikes a nerve. I think it's just the original post. Maybe it's the feeling projected by some of the participants in this thread that this can be a very very efficient algorithm that may approach O(1)?? when in fact, it's O(n) at best. How do I know this? Quite simply, if you are presented a list without knowing anything about it prior and nothing can be deduced from any value from that list about other values contained therein, then EVERY value in the list must be checked. In short, yes you absolutely MUST iterate over the entire hash. grep does it. A for loop will do it. Maybe you can sort the values, nuh uh...that iterates over the entire hash (values, mind you...but with this option, why aren't you using grep?). Even the setup with the insertion value counter must do it (although, only once instead of repeating). The only benefit there is that you don't need to repeat a count everytime you insert values. Of course, the cost is pretty much creating your own mechanism to catch all changes to said hash.

I don't know. It seems all this week I've been running into programmers who think you can squeeze blood out of a turnip. This is the fifth time I've seen this particular topic within a week. The last time was 15 minutes ago before I opened Perl Monks to settle down from having to convert the unbelieving (Who's been working on making his item counter faster for the past 3 hours. Three hours!!! !@$%!@#$^. Three hours trying to make something faster than grep which was based upon creating an array and sorting!! And he has a deadline coming up Tuesday and he "might get it done by then"). And then I open my browser, check out seekers of perl wisdom and... *sigh*. Sorry to lash out. I just felt that someone had to say it.

If I hurt anyone's feelings, I'm truly sorry. I'm just trying to vent and be somehow reassured that someone else can see what I see :-/

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1


In reply to Re: Counting keys with defined or undefined elements in a hash by antirice
in thread Counting keys with defined or undefined elements in a hash by Bukowski

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.