Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Difference my and local

by gopalr (Priest)
on May 25, 2005 at 02:05 UTC ( [id://460211]=note: print w/replies, xml ) Need Help??


in reply to Difference my and local

Hello

my:
your subroutine needs temporary variables. You shouldn't use global variables, because another subroutine might also use the same variables.

local:
All subroutines called from the context of a local variable can access that variable.

$a='one'; $b='two'; sub1(); sub sub1 { local $a = 'three'; my $b = 'four'; sub2(); } sub sub2 { print "\$a: $a\n"; print "\$b: $b\n"; }

Output

$a: three $b: two

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://460211]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-25 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found