in reply to Re^2: ref to read-only alias ... why? (notabug)
in thread ref to read-only alias ... why?
I'd document it pretty much as I already described it. Passing a read-only value or a literal constant to something that makes aliases (for, a sub) may decide to make an alias to the read-only value or may decide to make a copy of it. The decision might even be different in those two case (a literal constant vs. some other read-only scalar). The choice is a matter of optimization and subtle edge cases and Perl code should not depend on either specific behavior. Both behaviors have existed in many different versions of Perl.
No, I don't consider it a bug that some versions of Perl don't die in the face of:
sub add1 { return ++$_[0]; } my $two= add1(1);
Despite the use of "++" over "1+" there being questionable. It does have the interesting and perhaps useful side effect of allowing: add1($count). Yes, it is a contrived example. As is yours.
I don't find it hard to imagine cases where either result would be preferred. I do find it hard to imagine cases where either result is a serious problem that I wouldn't just address with a better interface for the subroutine.
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: ref to read-only alias ... why? (notabug)
by dk (Chaplain) on Jan 06, 2012 at 17:07 UTC | |
by tye (Sage) on Jan 06, 2012 at 19:12 UTC | |
by LanX (Saint) on Jan 06, 2012 at 19:55 UTC | |
by tye (Sage) on Jan 06, 2012 at 22:34 UTC | |
by LanX (Saint) on Jan 09, 2012 at 21:46 UTC | |
by dk (Chaplain) on Jan 06, 2012 at 20:45 UTC |