in reply to Comparing two hashes for duplicate keys with no case sensitivity

Few ideas:

I'm so adjective, I verb nouns!

chomp; # nom nom nom

  • Comment on Re: Comparing two hashes for duplicate keys with no case sensitivity

Replies are listed 'Best First'.
Re^2: Comparing two hashes for duplicate keys with no case sensitivity
by Tanktalus (Canon) on Aug 15, 2008 at 14:19 UTC

    In order:

    • Avoid regular expressions when matching. No matter how fast the gurus make the engine, it'll never beat eq for a full, exact match (though it may tie eq). And it'll never catch up with a hash lookup. And it can easily get convoluted (see Regexp::Common). Don't avoid it, of course, when it provides the power you need. But when lc and eq or index provide all the power you need, use them. The regular expression engine provides a lot of power a domain-specific language (DSL). So does a nail gun. Don't forget your other tools when they're more appropriate.
    • Good idea. But you don't really want to go through a second list to find matches from a first list. You don't want a loop in a loop - that becomes O(n^2). Instead, if you can construct the second list as a hash as toolic does (O(n) time), and then loop through the first list (O(n) time) looking each one up in the generated hash with your morphing function (in this case, lc or uc) which is O(1) time, you'll get O(n + n * 1) = O(2n) = O(n) time. Much faster. Now, maybe this is what you're suggesting, but in your race to be the first poster, you missed some helpful details ;-)
    • Super Search for what? Help Super Search Newbies out a bit by giving them a clue as to what to look for. If you don't know, be more gracious about it and admit so ;-) "I'm sure that Super Search would turn something up - did you try that?" It's always better if you've tried it and found things, though, especially since now Super Search will give you a perlmonks-style link ([href://...]) that contains the search terms you've used.
    (That said, welcome to the monastery - you're starting to get the hang of things now.)

      Thanks for the corrections :D
      Few comments:

      "Avoid regular expressions when matching."

      Isn't that the point of them though? Don't we use them to match things?

      "Now, maybe this is what you're suggesting"

      Sure was.

      "but in your race to be the first poster, you missed some helpful details"

      Sure did ;P

      "Help Super Search Newbies out a bit by giving them a clue as to what to look for."

      Will do!

      (Oh, and thanks for the welcome. One and a half months to almost catch on to the norm. Not bad eh?)

      I'm so adjective, I verb nouns!

      chomp; # nom nom nom