Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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
Replies are listed 'Best First'.
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 perusing the Monastery: (15)
As of 2015-07-29 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls