Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: scoping across parent/child relationship

by demerphq (Chancellor)
on Aug 30, 2001 at 22:49 UTC ( [id://109171]=note: print w/replies, xml ) Need Help??


in reply to scoping across parent/child relationship

geektron: the variables declared in the child process are only used in sub Initialize and in sub do_child_stuff, so I would think that the scope is valid... Nope. Other people have explained why so I wont comment. But I was wondering why you dont pass them as parameters to the functions? Then scoping doesnt become a problem:
my ( $foo, %bar, $bax ); Initialize_child($foo,\%bar,$bax); do_child_stuff($foo,\%bar,$bax);
or with named parameters:
sub Init_Child { my %params=@_; #blah } Init_Child(name=>$foo,attribs=>\%bar);

Yves
--
You are not ready to use symrefs unless you already know why they are bad. --tadmc (CLPM)

Replies are listed 'Best First'.
Re: Re: scoping across parent/child relationship
by geektron (Curate) on Aug 30, 2001 at 23:57 UTC
    But I was wondering why you dont pass them as parameters to the functions? Then scoping doesnt become a problem

    because i need them in both subs, and the actual variables are ( rather large ) config hashes. they can be global to the child ( if that makes sense )....

    just trying to get the most out of laziness...

      Sorry but thats not a good reason. Pass them by reference, or in a hash, or even create an object that bundles them all together into a nice package.
      Globals vars are evil without very very good justification. There is almost always an easier and safer way to do things.
      Almost the only time I use them is for things like a $Debug variable in a package.

      OTOH, its your code.... :-)

      Yves
      --
      You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)
      Then why not pass them as ref's?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found