Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Using a regex as a hash key

by ikegami (Patriarch)
on Jun 06, 2007 at 16:57 UTC ( [id://619628]=note: print w/replies, xml ) Need Help??


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

%functions is a Tie::RegexpHash, not a normal hash.

Replies are listed 'Best First'.
Re^3: Using a regex as a hash key
by halley (Prior) on Jun 06, 2007 at 17:04 UTC
    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 ]

      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.

Log In?
Username:
Password:

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

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

    No recent polls found