|
|
| P is for Practical | |
| PerlMonks |
Re: ~~ and list literalby ikegami (Pope) |
| on Oct 25, 2012 at 22:21 UTC ( #1000956=note: print w/ replies, xml ) | Need Help?? |
|
First, why what you have there doesn't work. The arguments of ~~ are necessarily evaluated in scalar context. ($x ~~ @a is just a shorthand for $x ~~ \@a.) That means that ~~ ("x", "y", "z") is equivalent to ~~ "z", as you were advised by warnings. Secondly, getting the behaviour you do want. Well, you want the SCALAR ~~ ARRAY behaviour, so you'll need an reference to an array, so you'll need an array. "x" ~~ ["x", "y", "z"] and "x" ~~ any("x", "y", "z") are the most concise means of achieving that with ~~. (any provided by Smart::Match). If you don't mind moving away from ~~, you could also use grep "x" eq $_, ("x", "y", "z").
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||