On Mar 2, 2013, at 6:37 AM, Chris Stinemetz wrote: > With Shlomi's approach how would I access each element in the %global_hash > within the main script calling the function? > > Below is what I have attempted. > > **Containers.pm** > > ## This is the file Containers.pm > package Containers; > > use parent 'Exporter'; > > our @EXPORT = (qw(get_global_hash)); > > my %global_hash = ( > 'donald' => 'duck', > 'mickey' => 'mouse', > 'goofy' => 'dog', > ); > > > sub get_global_hash > { > return \%global_hash; > } > > 1; > > **try.pl** > > #!/usr/bin/perl > use warnings; > use strict; > use Data::Dumper; > > use Containers; > > print "Hello", "\n"; > > # our %global_hash; > > print get_global_hash; > > # print Dumper \%global_hash; > >
You would save a reference to the hash in a local variable: my $global_hash_ref = get_global_hash(); Then you can deference the hash reference to access individual values: my $name = $global_hash_ref->{'donald'}; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/