I have
@a = (1,2,3); print (@a ~~ (1,2,3))
and
@a = (1,2,3); print (@a == (1,2,3))
The first one is the one I expect to work, but it does not print anything. The second one does print 1.
Why? Isn’t the smart matching operator ~~ supposed to match in the case of @a ~~ (1,2,3)?
For a second, lets consider the slightly different
~~evaluates its arguments in scalar context, so the above is the same as\@a(in any context) returns a reference to@a.1, 2, 3in scalar context is similar todo { 1; 2; 3 }, returning3.So minus a couple of warnings*, the above is equivalent to
What you actually want is
which can be shortened to
Finally, the magic of
~~allows\@ato be written as@a, so that can be shortened further to* — Always use
use strict; use warnings;!