in reply to Re: The Art of Hashing
in thread The Art of Hashing

1. For perl hashes, the only way to get matching keys of a hash for a given string, is performing a pattern match on the entire set of keys.
my @matching_keys = grep /$customer/, keys %Customer;

As some guy who used to be famous around here once said: "that's like buying and Uzi and using it to club your enemy to death".

It's also very misleading because the hash is serving no useful purpose in that construct.

It would be considerably cheaper to put the list of keys into an array and grep that than force Perl to re-walk the hash structure to generate the list of strings for grep each time around.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: The Art of Hashing
by shmem (Chancellor) on Jun 16, 2014 at 13:01 UTC

    Of course I can't but fully agree with you and thank you for the critic.
    Yes, storing the keys in an array is much cheaper - and partial match isn't what perl hashes are made for; that's better done with BTREE structures.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^3: The Art of Hashing
by CountZero (Bishop) on Jun 16, 2014 at 16:49 UTC
    that's like buying and Uzi and using it to club your enemy to death
    Indeed, an UZI is a very bad choice for a club. I'd suggest an AK47 or an M16. A Lee Enfield or a Mauser 98K, is an even better choice.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics