develooper Front page | perl.perl5.porters | Postings from December 2010

Re: [perl #80306] Quoting behaviour of => is too generous

Thread Previous | Thread Next
From:
Ed Avis
Date:
December 6, 2010 08:05
Subject:
Re: [perl #80306] Quoting behaviour of => is too generous
Message ID:
loom.20101206T165742-881@post.gmane.org
Abigail <abigail <at> abigail.be> writes:

>You seem to be assuming that C<< -aa => 1 >> quotes the C<< -aa >>. 
>It doesn't. It quotes the C<< aa >>:
>
>  $ perl -MO=Deparse -wce 'my %h = (12 -aa => 1)'
>  BEGIN { $^W = 1; }
>  my(%h) = (12 - 'aa', 1);
>  -e syntax OK

Yes, I see (the runtime error message also indicated this).  Is that intentional?
It does not do that in the case without the extra argument in front:

  $ perl -MO=Deparse -wce 'my %h = ("-aa" => 1)'
  BEGIN { $^W = 1; }
  my(%h) = ('-aa', 1);

It's a bit odd for the quoting behaviour to differ like this - or at least, I
would expect that if => has the effect of quoting its LHS, then it should also
bind to it a bit more tightly.

Separately, it would be useful in some cases to generate a compile-time warning
for code liked

    my $x = 12 - 'aa'

After all this is a constant expression and will warn at runtime.

-- 
Ed Avis <eda@waniasset.com>


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