perl - passing hash in subroutines -
i have made simple perl script printing hash key/value pairs through subroutine
#!/usr/local/bin/perl #passing hash subroutine sub printhash{ (%hash) = @_; foreach $key (keys %hash){ $value = $hash{$key}; print "$key : $value\n "; } } %hash = {'name' => 'devendra', 'age' => 21}; printhash(%hash); expected output:
name : devendra
age : 21
ouput:
hash(0x1be0e78) :
what wrong it?
this line
%hash = {'name' => 'devendra', 'age' => 21}; is attempting assign anonymous hash reference hash. mean is
%hash = ('name' => 'devendra', 'age' => 21); if had use strict , use warnings have seen message
reference found even-sized list expected
cluing in problem. use them!
Comments
Post a Comment