Your message dated Sun, 8 Jan 2012 19:03:23 +0000
with message-id <[email protected]>
and subject line Re: Bug#655063: syntax error not caught ($h+=9)=(3)
has caused the Debian Bug report #655063,
regarding syntax error not caught ($h+=9)=(3)
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
655063: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=655063
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: perl
Version: 5.14.2-6
Severity: wishlist

The first syntax error is caught, but not the next, even with use strict.

$ perl -lwe '($h{a}+ 9,$h{f})=(3,2); print for values %h'
Can't modify addition (+) in list assignment at -e line 1, near ");"
Execution of -e aborted due to compilation errors.
$ perl -lwe '($h{a}+=9,$h{f})=(3,2); print for values %h'
3
2
$ perl -lwe 'use strict;my %h;($h{a}+=9,$h{f})=(3,2); print for values %h'
3
2
$ perl -lwe 'use strict;my $h;($h+=9,undef)=(3,2); print $h'
3
$ perl -lwe 'use strict;my $h;($h+=9)=(3); print $h'
3

If it is not a syntax error then it should be.



--- End Message ---
--- Begin Message ---
On Sun, Jan 08, 2012 at 10:14:38AM -0800, Russ Allbery wrote:
> [email protected] writes:
> 
> > $ perl -lwe 'use strict;my $h;($h+=9)=(3); print $h'
> > 3
> 
> > If it is not a syntax error then it should be.
> 
> If Perl were a different language with different semantics, it could be a
> syntax error, but it's not.  I don't see how that could be a syntax error
> without changing the way Perl works in ways that wouldn't be backward
> compatible.
> 
> The expression "$h += 9" adds 9 to $h and then returns $h as an lvalue
> (meaning that it can be assigned to again).  This is because "$h += 9" is
> entirely equivalent to "$h = $h + 9" and assignment returns an lvalue, as
> documented in perlop:
> 
>        Unlike in C, the scalar assignment operator produces a valid lvalue.
>        Modifying an assignment is equivalent to doing the assignment and then
>        modifying the variable that was assigned to.  This is useful for
>        modifying a copy of something, like this:
> 
>            ($tmp = $global) =~ tr [0-9] [a-j];
> 
>        Likewise,
> 
>            ($a += 2) *= 3;
> 
>        is equivalent to
> 
>            $a += 2;
>            $a *= 3;
> 
> The expression "($h += 9)" is therefore a list of lvalues containing one
> lvalue, and you can assign a list of values to a list of lvalues in Perl.
> (If you couldn't, the expression "my ($a, $b) = (1, 2)" wouldn't work,
> which would break a ton of Perl code.)  Also, this expression is very
> similar to the "($a += 2) *= 3" expression that's explicitly documented as
> working in perlop.
> 
> So while this is confusing, this is the language working as it is
> documented to work.

Hi Russ,

Thanks for taking the time to explain this. I'm now resolving this bug
report.

Cheers,
Dominic.

-- 
Dominic Hargreaves | http://www.larted.org.uk/~dom/
PGP key 5178E2A5 from the.earth.li (keyserver,web,email)


--- End Message ---

Reply via email to