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

Re: using strict and functions

by mirod (Canon)
on Jan 17, 2002 at 22:40 UTC ( #139586=note: print w/ replies, xml ) Need Help??


in reply to using strict and functions

You can also declare a global hash (or array, but a hash is more convenient) containing the variables and pass it around as a parameter to the functions:

my $state= { var1 => "value1", var2 => "value2"}; sub f1 { my( $other_param, $state)= @_; $state->{var2}= "new_value2"; # ... } ...

This way you group the variables together cleanly and you can pass them to the functions without clobbering your parameter lists.

Of course if you want to get OO brownie-points you can also make $state an full-blown object, but that would be an other story node...


Comment on Re: using strict and functions
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-10-24 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (134 votes), past polls