Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Behaving appropriately based on ref() result

by esskar (Deacon)
on Jan 08, 2006 at 14:46 UTC ( #521822=note: print w/ replies, xml ) Need Help??


in reply to Behaving appropriately based on ref() result

use a Hash

my %RefTypes = ( 'Regexp' => \&HandleRegexp, 'CODE' => \&HandleCodeRef, 'ARRAY' => \&HandleArrayRef, 'HASH' => \&HandleHashRef, 'SCALAR' => \&HandleScalarRef, '' => \&HandleScalar, ); my $ref = ref($_); if(exists $RefTypes{$ref}) { $RefTypes{$ref}->($_); } else { warn "Unknown ref() wth is a $ref ?!"; }
HTH


Comment on Re: Behaving appropriately based on ref() result
Download Code
Re^2: Behaving appropriately based on ref() result
by suaveant (Parson) on Jan 09, 2006 at 05:00 UTC
    Just for reference using a hash this way is called a dispatch table.

                    - Ant
                    - Some of my best work - (1 2 3)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (18)
As of 2014-07-30 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (234 votes), past polls