in reply to Re^5: Order of evaluation/interpolation of references
in thread Order of evaluation/interpolation of references
I don't understand why you are so upset about this behavior.
I'm not upset. I just don't think it can be explained away as coder error.
There are good reasons why some languages work hard on being side-effect free.
Perl is not one of those languages.
X() has side-effects causing problems and I have problems imagining any practical application of this pattern. Or could you show me a reason to return the reference of the same static closure variable instead of the value itself?
Because the string is huge and you want to avoid copying it twice.
Nobody thinks twice about returning a reference to an array or hash to avoid unnecessary copying:
C:\test>perl -E"{my@x; sub X{ push@x,'some interesting value';;\@x}}; +say qq[@{X()}@{X()}]" some interesting valuesome interesting value some interesting value
which behavior is wrong and which is right?
NB: there are 3 interesting values above, not four. Is that debatable?
|
|---|