Once again, you have correctly corrected me. :-) Thanks.
I didn't happen to notice that OP was passing a reference, so, as you say, the issue was moot. On the other hand, whilst you are right that Perl passes by reference and I am grateful for the correction, the usual semantics of parameter usage does involve copies that can clobber a passed in tied scalar:
In this code sample, which compares the usage of a parameter array element directly ($_[0]) with one common usage of the array ($param = shift @_)
we get the following output
using @_ directly
$_[0] is tied to <TiedObject=ARRAY(0x814ed48)>
after $param0 = shift @_
$param0 is not tied
Best, beth | [reply] [d/l] [select] |
You thought the variable was being passed directly, so you believed the SV was being passed by reference. In the same breath, you said tied variables don't work because SVs are passed by value. I called fouled on the latter, so I don't see how the typical practices of subs are of any consequence here.
Furthermore, we weren't talking about subs, so the typical practices for writing subs are completely irrelevant. (Builtin and other XS) functions access the SV directly until a specific native type is needed. I don't think I've ever seen one that copies the arguments on entry. Remember, the primary purpose of copying the args in subs is to provide named parameters, but functions already have named parameters.
| [reply] |
Actually, I was talking about subs (though I realize now I may have confused you by using the word sub/function interchangably). From my original reply:
When scalars are passed to a function, e.g. open they are copied (not passed by reference).
I was wrong about them not being passed by reference to subs/functions (i.e. the calling convention), but not about them being copied, at least when people use the parameters the usual way. I was mistaken precisely because whenever I define subs I never use @_ directly. As a result, I formed a long standing misimpression of the calling convention. I simply didn't want others to make the mistake I did or to think that they could freely pass tied scalars into subs (or functions) without knowing how they were going to be used internally.
As for "crying foul" - that makes this sound like a fight. I'm here to learn, not to argue. Perhaps those aren't your goals?
In my opinion, trying to understand why someone made a mistake is as important as correcting them. And for me, it is an essential part of not repeating my own. I never was much of a rote learner.
Best, beth
| [reply] [d/l] |