Vizible’s Blog

Perl – How to dereference hash?

Posted in Programming by wearetherock on July 22, 2009
sub doHash {
        #get hash reference
        my $animalRef = shift;

        #dereference hash
        my %animal = %$animalRef;

        print $animal{BIRD};
}
%animal = ( BIRD => 2, PIG => 4, DOG => 4 );

#pass animal as reference
doHash(\%animal)
Advertisements
Tagged with:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: