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

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

Thread Previous | Thread Next
From:
Tony Cook
Date:
March 16, 2021 00:15
Subject:
Re: Perl feature wish: quote-word array-ref operator
Message ID:
20210316001534.GC20753@venus.tony.develop-help.com
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
minus.

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

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

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)

Tony

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About