#!/usr/bin/perl
my %hs;
$hs{"one"} = 1;
$hs{"two"} = 2;

sub pr
{
my $ref = $_;

foreach $key (sort keys %$ref)
{
print "$key = ${$ref{$key}}"; }
}

pr(\%hs);

This should work..

--
Ankur

Hou Feng.Leo wrote:

> Dear all,
> I want to pass a hash to a function which prints out hash's content.
> My code does not work. Can anyone tell me what is wrong with it?
> Thanks a lot
>
>
> #!/usr/bin/perl
> my %hs;
> $hs{"one"} = 1;
> $hs{"two"} = 2;
>
> sub pr
> {
> my $ref = $_;
>
> foreach $key (sort keys %ref)
> {
> print "$key = $ref{$key}"; }
> }
>
> pr(\%hs);
>
>
>

Reply via email to