in reply to Ambiguous '~~' in 'print scalar ~~list'

Hello rsFalse,

Yes, the parser is interpreting ~~ as the smartmatch operator here:

23:30 >perl -MO=Deparse 1983_SoPW.pl Smartmatch is experimental at 1983_SoPW.pl line 9. BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict; @_ = ('a', 'b', 'c'); open my $A, '>', 'out.txt'; print $A ~~ \@_; print $A scalar @_; 1983_SoPW.pl syntax OK 23:30 >

But if you really want to parse this construction as the so-called “inchworm operator,” just use parentheses — print $A (~~@_); — to disambiguate:

23:32 >perl -MO=Deparse 1983_SoPW.pl BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict; @_ = ('a', 'b', 'c'); open my $A, '>', 'out.txt'; print $A ~~@_; print $A scalar @_; 1983_SoPW.pl syntax OK 23:32 >

As to which interpretation should be given “higher precedence” by the parser: that really depends on the way the two constructs are expected to be used. And in fact the double tilde was never intended to be used as an operator at all. If the smartmatch experiment had been successful (it wasn’t), it would have intentionally introduced a new operator into Perl. So of course the parser is going to treat ~~ as a smartmatch operator wherever that makes syntactic sense — that’s what the experiment was all about.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,