I have three hashes named %hash1, %hash2, %hash3. I need to reference each hash by variable and am not sure how to do it.
#!/usr/bin/perl
# Hashes %hash1, %hash2, %hash3 are populated with data.
@hashes = qw(hash1 hash2 hash3);
foreach $hash(@hashes){
foreach $key(keys $$hash){
.. Do something with the hash key and value
}
}
I know this is a fairly simplistic, comparatively noob question so my apologies for that.
This should work for you.
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.