develooper Front page | perl.perl5.porters | Postings from March 2021

Re: Perl feature wish: quote-word array-ref operator

Thread Previous | Thread Next
Tony Cook
March 16, 2021 00:15
Re: Perl feature wish: quote-word array-ref operator
Message ID:
On Fri, Mar 12, 2021 at 10:35:34AM +0100, H.Merijn Brand wrote:
> But the fat comma already makes an exception for leading dashes:
> $ perl -MData::Dumper -E'say Dumper ({ -key => 42, -value => "Boo" })'
> $VAR1 = {
>           '-key' => 42,
>           '-value' => 'Boo'
>         };
> So it *is* possible. I have no idea what the impact would be and I did
> not yet make up my mind if I want it myself.  Also no idea how much it
> would break (no breakage is an option to consider).

That's not the fat comma making an exception, it's just the fat comma
barewording the previous token, and the "normal" behaviour of unary

There *is* a general exception for - before a bareword:

  $ perl -Mstrict -le 'my $x = -foo; print $x'

but even if I hack that out (see the last few lines of
S_op_integerize() in op.c):

  $ ./perl -Ilib -Mstrict -e 'my $x = -foo'
  Bareword "foo" not allowed while "strict subs" in use at -e line 1.

the fat comma version still works:

  $ ./perl -Ilib -Mstrict -e 'my %x = ( -foo => 1 )'
  (no error here)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About