in reply to Re: style q: duplication? of variables
in thread style q: duplication? of variables
Ouch. chastised in the chatterbox, i've digested all this and read a bit more thoroughly than before. I now understand that the creation of a new variable happens at this stage:
my ($text) = @_;Which is embarrassingly obvious once realised. And that when I
return $text;I am returning the new - local - entity and not the original one, so back in main::, the $text variable is now pointing to the value that was created in and returned from the sub. (Dominus' very lovely explanation of scope and duration was helpful here. That one really ought to be in best nodes.)
And the reason things are different with references is that a duplicate of a reference points to the same piece of data as the original. There is still duplication, but only of pointers, not data.
Thought i'd better put things straight before i get told off any more. Thanks for all the answers.
|
---|