Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Behaving appropriately based on ref() result

by esskar (Deacon)
on Jan 08, 2006 at 14:46 UTC ( [id://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

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://521822]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-18 02:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found