On Monday, April 8, 2002, at 07:28 , Timothy Johnson wrote:
[..]
> If you just pass the value,
> then any operations performed on your variable in the subroutine will be
> destroyed when the sub exits.  This way you will be performing all
> operations on the original variable, allowing you to change it as if it 
> were
> in scope.
[..]

p1: thank you for the illustration of pass by reference, vice
the traditional 'pass by value' approach I normally do with say

        sub myFunc { my ($var) = @_ ; .... }

p2: I also noticed that I could access the upper level $var inside
the PrintSub function.... but that using the simple

        my $subvars = ${$_[0]}; #dereference the reference you passed.

did not mean that
        
        $subvar = ":The Other String:";

would actually change the value in 'the main'. To do that I needed
to specifically do

        my $ref = $_[0];
        ...
        ${$ref} = $subvar ;

cf:

http://www.wetware.com/drieux/CS/lang/Perl/Beginners/sub_ref.txt

which generates
        starting Var is :The String Value:
        SUB: $subvar is now :The String Value:.
        SUB: $var is now :The String Value:.
        MAIN: $var is now :The String Value:.
        SUB: $subvar is now :The String Value:.
        SUB: Reset $subvar to :The Other String:.
        MAIN: $var is now :The Other String:.


ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to