develooper Front page | perl.perl5.porters | Postings from April 2019

scalar propagates lvalue context?

Thread Next
From:
demerphq
Date:
April 26, 2019 10:58
Subject:
scalar propagates lvalue context?
Message ID:
CANgJU+VfLW3LCbm=-kV6EKOi_kyLTQm4ajtnSukf3+mARGd0kA@mail.gmail.com
Hi, it was recently brought to my attention that scalar now propagates
lvalue context (As of v5.22 apparently). Personally I struggle to
understand why this is a good thing, and I think the following
demonstrates how it is not thought through:

$ perl -le'scalar($#foo)=10; print $#foo'
Can't modify scalar in scalar assignment at -e line 1, near "10;"
Execution of -e aborted due to compilation errors.
$ perl -le'for (scalar($#foo)) { $_=10 }; print $#foo'
10

This is from Perl 5.28.1.

If I cant assign to scalar($#foo) directly, then I shouldnt be able to
wrap it in a for loop and assign to it indirectly.

Something here does not make sense.

cheers,
Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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