qbxk has asked for the wisdom of the Perl Monks concerning the following question:
here's an mini-example:
my $ref = ref($_); if( $ref eq 'Regexp' ) { #ah, we are matching a match } elsif( $ref eq 'CODE') { #sombody slipped a sub{} in here, ok } elsif( $ref eq 'ARRAY') { #an @array we have found } elsif( $ref eq 'HASH') { #a %hash, obviously } elsif( $ref eq '') { #must be a $scalar } else { warn "Unknown ref() wth is a $ref ?!"; }
My question for the clergy is: what's a more elegant way to accomplish this? or what is your favorite idiom for this task?
also, have i hit on all the possible values that ref() can return?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Behaving appropriately based on ref() result
by esskar (Deacon) on Jan 08, 2006 at 14:46 UTC | |
by suaveant (Parson) on Jan 09, 2006 at 05:00 UTC | |
|
Re: Behaving appropriately based on ref() result
by tirwhan (Abbot) on Jan 08, 2006 at 14:55 UTC | |
|
Re: Behaving appropriately based on ref() result
by dragonchild (Archbishop) on Jan 08, 2006 at 16:22 UTC | |
by demerphq (Chancellor) on Jan 09, 2006 at 09:11 UTC | |
|
Re: Behaving appropriately based on ref() result
by McDarren (Abbot) on Jan 08, 2006 at 14:44 UTC | |
|
Re: Behaving appropriately based on ref() result
by demerphq (Chancellor) on Jan 09, 2006 at 09:04 UTC | |
by suaveant (Parson) on Jan 09, 2006 at 15:00 UTC | |
|
Re: Behaving appropriately based on ref() result
by bsb (Priest) on Jan 09, 2006 at 07:52 UTC | |
by demerphq (Chancellor) on Jan 09, 2006 at 08:46 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |