Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: using if-elsif-else

by chargrill (Parson)
on Dec 29, 2006 at 04:43 UTC ( [id://592168]=note: print w/replies, xml ) Need Help??


in reply to Re: using if-elsif-else
in thread using if-elsif-else

I was operating under the assumption that a user could enter "Kevin Johnson" and still get the value for $phnums{'kevin'} - i.e. more than what might be used as the explicit hash key. Possibly a poor assumption, but I couldn't think of a better reason for using regexen in the OP's code :-)

I recently ran across a hash setup as a dispatch table where most values were well defined, but some could match a variety - these were handled (in a generalized manner) like so:

if( exists $hash{$key} ){ &$hash{$key}; } elsif( $key =~ /phrase/ ){ # several could match but all required the same action &$hash{'some_action'}; } else { &$hash{'default_action'}; }


--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Replies are listed 'Best First'.
Re^3: using if-elsif-else
by thevoid (Scribe) on Dec 29, 2006 at 10:39 UTC
    I was operating under the assumption that a user could enter "Kevin Johnson" and still get the value for $phnums{'kevin'} - i.e. more than what might be used as the explicit hash key.

    You're right, that was the idea :-) Thanks for the alternative code.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-16 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found