Don't do that. Well, not substitute a hash for bunch of global variables anyway. Instead use a light weight object:
use strict;
use warnings;
my $obj = bless {};
$obj->initMembers ();
$obj->print ();
sub initMembers {
my ($self) = @_;
$self->{hello} = "Hello World.\n";
}
sub print {
my ($self) = @_;
print $self->{hello};
}
The idea is to make the 'globals' into 'data members' so that their provenance is clear and avoid passing around a hash as a parameter everywhere (the member calling mechanism is doing that implicitly).
Don't get caught by the run time 'efficiency' snare. Any timing difference at the level you are asking about is so small that you can ignore it. Programmer efficiency gains are where you should be looking and that boils down to code that is easy to test and maintain. Writing tests for your code as you write the code is a strongly recommended practice.
True laziness is hard work
|