This should work for you.
#!/usr/bin/perl
use strict;
use warnings;
my( %hash1, %hash2, %hash3 );
# ...
# load up %hash1 %hash2 and %hash3
# ...
my @hash_refs = ( \%hash1, \%hash2, \%hash3 );
for my $hash_ref ( @hash_refs ){
for my $key ( keys %$hash_ref ){
my $value = $hash_ref->{$key};
# ...
}
}
It uses hash references, instead of using symbolic references. It is very easy to get symbolic references wrong, and can be difficult to debug.
This is how you could have used symbolic references, but I would advise against it.
#!/usr/bin/perl
use strict;
use warnings;
# can't use 'my'
our( %hash1, %hash2, %hash3 );
# load up the hashes here
my @hash_names = qw' hash1 hash2 hash3 ';
for my $hash_name ( @hash_names ){
print STDERR "WARNING: using symbolic references\n";
# uh oh, we have to turn off the safety net
no strict 'refs';
for my $key ( keys %$hash_name ){
my $value = $hash_name->{$key};
# that was scary, better turn the safety net back on
use strict 'refs';
# ...
}
# we also have to turn on the safety net here
use strict 'refs';
# ...
}