Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: nested Subroutines and my var

by ambs (Pilgrim)
on Mar 28, 2005 at 19:47 UTC ( #442930=note: print w/replies, xml ) Need Help??

in reply to nested Subroutines and my var

Update: Changed accordingly with Roy Johnson reply. I hope I understood correctly what he means. What you say about my vars is correct. If you want a variable to be accessible for other functions calls, use:
our $bar; sub foo { local $bar = 4; # different $bar zbr(); } sub zbr { print $bar; }
This code prints 4.

The correct way is to pass parameters to functions.

Alberto Simões

Replies are listed 'Best First'.
Re^2: nested Subroutines and my var
by Roy Johnson (Monsignor) on Mar 28, 2005 at 20:05 UTC
    Note that our does not create variables, it merely tells Perl that you're going to be using the global variables you list. You should put the our outside of foo, and use local inside it. Then you're strict safe.

    Caution: Contents may have been coded under pressure.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2021-10-27 14:13 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (93 votes). Check out past polls.