Link to home
Start Free TrialLog in
Avatar of Stapman
Stapman

asked on

shift for a hash?

I want to go through my hash
value for value but with foreach (%hash) $_ becomes a value then a key string then a value etc..


Is there a function for a hash which does the same as shift for an array?

Thanks
Avatar of RobWMartin
RobWMartin

Use this:

foreach (keys %hash)

then

$_ is the key to the hash, and, of course, $hash{$_} is the value.

ASKER CERTIFIED SOLUTION
Avatar of RobWMartin
RobWMartin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
#or
while( ($key,$value) = each %hash ){
    print "hash{$key} = $value\n";
}

#also, values %hash returns an array containing only the value of each hash entry
#(the same as @hash{keys %hash})