Hi, I am trying to pass a hash from a package to my script with the following. Can anyone tell me why it doesn't work? the_package.pm------------------- #!/usr/local/ActivePerl-5.6/bin/perl -w package the_package; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(%exp_hash); use WWW::Mechanize; use strict;
my %exp_hash;
You have declared your hash as a lexical as opposed to a package variable. To export the package variable of the same name you need to declare it as a package variable. You can do so by switching 'my' to 'our' (on older Perl's you will need 'use vars'),
perldoc -f my perldoc -f our
http://danconia.org
$exp_hash{val1}=1; $exp_hash{val2}=2; $exp_hash{val3}=2;
the_script.pl------------------------------------- #!/usr/local/ActivePerl-5.6/bin/perl -w use warnings; use strict; use the_package; my $value; foreach $value (keys %exp_hash) { print $exp_hash{$value}; } print $exp_hash{val1};
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>