in reply to Re^2: Using a regex as a hash key
in thread Using a regex as a hash key

ikegami, I recognized that it's a TRH, but it still behaves like a hash including iteration, as well as the extra features and odd non-1:1 key behavior. If he doesn't have anything for a key (his missing $val1), he'll have to start somewhere.

Perhaps I should have said he could just assign $val1 = 'Devices Configuration for Hard Drives' to pick out one particular key, or the hail-mary dispatch loop that citromatik offers where you just throw any old $_ in there and hope it sticks.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re^4: Using a regex as a hash key
by ikegami (Patriarch) on Jun 06, 2007 at 17:12 UTC

    Sorry, it sounds like I needed to be more explicit.

    %functions is a Tie::RegexpHash, so your suggestion of $functions{$regex}->($var2); is wrong — Use a normal has for that — and a step in the wrong direction. The key for lookups should not be a regexp, but a value to match against the existing keys.

    Looping over all the keys is even worse. The whole point of Tie::RegexpHash is to save you from doing that.