Although your original question was answered, no one seemed to address the fact that if you code with a little planning, you can preserve efficiency and use %hash for all of your non-module code.
Generally people write modules for whatever purpose and then only occasionally (if ever) go back and modify them. So use the references in the module and once it's finished, you can write as many programs as you like using %hash and still have efficient code. Here is an example module:
package mylib;
use strict;
use warnings;
use Exporter;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw( load_hash );
sub mylib::load_hash {
my $href = shift;
for (1..1000) {
$$href{$_} = $_;
}
}
And an example program that uses it:
#!/usr/local/bin/perl
use strict;
use warnings;
use mylib;
my %hash;
mylib::load_hash(\%hash);
for (keys %hash) {
print "key: $_ value: $hash{$_}\n";
}
--Jim