in reply to updated_again: how to loop through hash tables more efficiently

lrl1997:

A hash table lets you get a value given its name. So you don't need the second loop: You can use the exists function (see perldoc -f exists ) to check if the key is in the other hash.)

$ cat t my %h = (a=>1, b=>2, c=>3); print "a ", exists($h{a}) ? "exists" : "does not exist", "\n"; print "c ", exists($h{c}) ? "exists" : "does not exist", "\n"; print "f ", exists($h{f}) ? "exists" : "does not exist", "\n"; $ perl t a exists c exists f does not exist

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: how to loop through hash tables more efficiently
by Anonymous Monk on Sep 17, 2012 at 21:20 UTC

    So you don't need the second loop... You can use the exists function

    he is already using exists, your code doesn't map well to his example , his faux hash of arrays

      Oh, yes, I seem to have glossed over that. When I read it, I thought he was comparing keys with keys, rather than keys and values.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.