I have made a simple perl script for printing hash key/value pairs through subroutine
#!/usr/local/bin/perl
#passing hash to a subroutine
sub printhash{
my (%hash) = @_;
foreach my $key (keys %hash){
my $value = $hash{$key};
print "$key : $value\n ";
}
}
%hash = {'name' => 'devendra', 'age' => 21};
printhash(%hash);
Expected Output:
name : devendra
age : 21
Ouput:
HASH(0x1be0e78) :
What is wrong with it?
This line
is attempting to assign an anonymous hash reference to a hash. What you really mean is
If you had
use strict
anduse warnings
you would have seen the messagecluing you in to the problem. Always use them!