dragonchild has asked for the wisdom of the Perl Monks concerning the following question:
my %mapping = ( ARRAY => '@', HASH => '%', SCALAR => '$', # GLOB => '?', # REF => '?', # CODE => '?', ); if (grep { $_ eq $type } keys %mapping) { if (isa($_[0], $type)) { return eval "$mapping{$type}{$_[0]}"; } else { return @_; } } else { return (); }
The idea is to allow for someone to pass in either a list or a listref and the function will handle it transparently. (Don't ask why ... it's one of those creature feep things.)
Now, I originally wrote this as a bunch of if-elsif-elsif-else's, but realized that they were all the same, except for the $@% character. (Which brings me to a side question - how do I handle REF, CODE, and GLOB in this fashion?) I figure I should be doing some sort of eval here, but have no idea what.
Help?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Eval and $@% ...
by tye (Sage) on Jun 19, 2001 at 10:01 UTC | |
by dragonchild (Archbishop) on Jun 19, 2001 at 18:04 UTC | |
by tye (Sage) on Jun 19, 2001 at 22:33 UTC | |
by dragonchild (Archbishop) on Jun 20, 2001 at 00:09 UTC | |
by tye (Sage) on Jun 20, 2001 at 00:47 UTC | |
by wog (Curate) on Jun 20, 2001 at 00:44 UTC | |
|
Re: Eval and $@% ...
by jeroenes (Priest) on Jun 19, 2001 at 01:44 UTC | |
by bbfu (Curate) on Jun 19, 2001 at 01:57 UTC | |
by jeroenes (Priest) on Jun 19, 2001 at 02:09 UTC | |
by srawls (Friar) on Jun 19, 2001 at 05:11 UTC | |
by Abigail (Deacon) on Jun 19, 2001 at 09:56 UTC |