|
|
| There's more than one way to do things | |
| PerlMonks |
Smart matching for argument constraintsby LanX (Monsignor) |
| on Sep 03, 2012 at 13:45 UTC ( #991434=perlquestion: print w/ replies, xml ) | Need Help?? |
|
LanX has asked for the
wisdom of the Perl Monks concerning the following question:
Hi
I'm considering using the smart macht operator for argument constraints at the start of a sub. I have to admit that ~~ still confuses me a lot is the following code correct to check if 1. the argument is a simple scalar (that is no ref) 2. and element of the given set (here a b c)?
so e.g. tst(x => "a"); is ok. the explicit stringification (quotes) of "$arg{x}" is necessary to avoid tst(x => [qw/a b c/]); to be legal. Any comments? Any better idioms for checking arguments?
Cheers Rolf
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||