Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 musing on the Monastery: (15)
As of 2014-08-01 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (21 votes), past polls