http://qs1969.pair.com?node_id=521818

qbxk has asked for the wisdom of the Perl Monks concerning the following question:

Writing a function to traverse a "configuration" array I have a series of if/elsifs that switch based on what kind of data it encounters, ie. by whatever ref() returns.

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?


It's not what you look like, when you're doin' what you’re doin'.
It's what you’re doin' when you’re doin' what you look like you’re doin'!
     - Charles Wright & the Watts 103rd Street Rhythm Band