in reply to ~~ and list literal
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").
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: ~~ and list literal
by Anonymous Monk on Oct 25, 2012 at 23:26 UTC | |
by mbethke (Hermit) on Oct 26, 2012 at 01:49 UTC | |
Re^2: ~~ and list literal
by Anonymous Monk on Oct 25, 2012 at 23:46 UTC | |
by ikegami (Patriarch) on Oct 27, 2012 at 00:15 UTC | |
by mbethke (Hermit) on Oct 26, 2012 at 01:56 UTC | |
by Anonymous Monk on Oct 26, 2012 at 03:16 UTC |
In Section
Seekers of Perl Wisdom