Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Help.pm automatically explains how to use misused objects

by pKai (Priest)
on Jan 15, 2008 at 10:52 UTC ( [id://662446]=note: print w/replies, xml ) Need Help??


in reply to Re: Help.pm automatically explains how to use misused objects
in thread Help.pm automatically explains how to use misused objects

Having just seen an instance of iteration over a hash and getting values there on the basis of string equality tests against string constants from a co-worker (in VB.Net though, but the same argument applies of course)…

… maybe it's more common among programmer who grew up in an environment with arrays being the most advanced dynamic data structure?

On the other hand, I'm not sure what to make of the Club-Uzi-quote. The moment you get away from equality tests, because the particular key is only an abstraction of a wider class of strings which all have to refer to that particular value (e.g. case-insensitivity, internationalization, whatever) you are supposed to iterate over the keys (or the key-value-pairs) of the hash, aren't you?

Replies are listed 'Best First'.
Re^3: Help.pm automatically explains how to use misused objects
by Jenda (Abbot) on Jan 15, 2008 at 16:04 UTC

    Depends. Most often not. Most often you are supposed to use a datastructure that supports that. If you can't use an Uzi, use something heavier. In case you want a case insensitive hash ... there are modules for that on CPAN, if you want some other definition of equality, you can do something similar to what those modules do and if you want to process all items whose keys match some more complex condition you should probably already be using a database. Even if it was just SQLite.

    Of course that sometimes looping though all the keys&values is the only solution. And using anything else would either be an overkill or would not help anything, the point is that before you start looping you should be sure you have to. Before you start banging your Uzi over someone's head, you should make sure the Uzi is not loaded. To save time and to make sure you do not shoot yourself in the foot :-)

      Thank you very much for your comment.

      After some thinking and looking into things like Hash::Case and Tie::CPHash, tying and going for normalized keys internally is the way to go in my case also.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://662446]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-28 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found