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

scalar propagates lvalue context?

Thread Next
April 26, 2019 10:58
scalar propagates lvalue context?
Message ID:
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'

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.


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

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