Yep.  I guess I'm still a little groggy.  I think this whole "Spring
Forward" thing is a bit of a misnomer.

-----Original Message-----
From: drieux [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 08, 2002 8:07 AM
To: [EMAIL PROTECTED]
Subject: Re: Scope of variables. Lost in subs



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]


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

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

Reply via email to