in reply to How can I stop relying on a global variable?

You could put the setter and the function in a scope with the hash declared as a lexical. It would be available to them since they are in the closure. Something like this:
{ my %value_for; sub set_values { my ( $key, $value ) = shift; $value_for{ $key } = $value; } sub function { # ... my $special_value = $value_for{specialness}; # ... } }
So value_for is shared by just those two subs.

Phil

Replies are listed 'Best First'.
Re^2: How can I stop relying on a global variable?
by Anonymous Monk on Feb 03, 2006 at 19:12 UTC
    One thing I failed to mention: The function and the method are in different files. This code comprises a suite of modules working together. When writing modules, I normally don't like putting my methods in the same file as my functions. For example, this one particular method that alters the global hash belongs to a base class. And the function that checks the hash is exported by a module. Both the module and the base class are part of the application.
        Could you please elaborate? I have heard of "singleton classes" before but I don't know what they are. And how could one help me here?