Ouch! So you first specify a prototype for the printeElement subroutine (which you generally should not do unless you REALLY know what you are doing) and then call the subroutine with the & which turns the prototype off ... don't! Drop both the (\%$) and the & from the &printElement(....
Your problem is that the my %hash1 = %{($_[0])}; makes a copy of the hash and to make the copy it needs to iterate through the hash ... which resets the iterator position so the each() will always start from the beginning.
If you do insist on passing the key and the hash to your subroutine, do not make a copy! Work with the hash reference:
sub printElement { my $hash1 = $_[0]; my $key = $_[1]; print $key." ".$hash1->{$key}."\n"; }
Jenda
Enoch was right!
Enjoy the last years of Rome.
In reply to Re: subroutine reference parameters
by Jenda
in thread subroutine reference parameters
by dnajjar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |