in reply to Pass data to a Module

In addition to grep's comments about references, I happened to notice this:

I haven't declared them as my or local in the main script ...

What is probably going on is that you are expecting these variables to be global, but you probably haven't taken into account the namespace. This implies to me that you are likely not using strict. I can't prove that (you didn't post your code), but it has been my experience that someone who is unfamiliar with package declarations or who (ab)uses globals is unlikely to be familiar with strict. Please read 'use strict' is not Perl. You may not like what you read, but it will save you grief in the long run. In the meantime, you can follow grep's advice. However, I would make a tiny change to his syntax:

sub foo { my ($hash1,$hash2) = @_; # cleaner dereference foreach (keys %$hash1) { print "$_ $hash1->{$_}\n"; } # preferred, if you need to access both while ( my ($key, $value) = each %$hash2 ) { print "$key $value\n"; } }

The first loop uses the arrow syntax to dereference (cleaner, and easier to read, in my opinion) and the second loop uses the each iterator to get at the values (another "clean" method).

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.