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
StapmanAsked:
Who is Participating?
 
RobWMartinCommented:
I guess I should explain.  The keys function returns an array containing only the key of each hash entry.

For details:

perldoc -f keys


Rob
0
 
RobWMartinCommented:
Use this:

foreach (keys %hash)

then

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

0
 
ozoCommented:
#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})
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.