each expects a hash (or array with "newer" perls).
The %{} does dereferencing of the enclosed expression, which needs to be evaluated.
There is no way to tell for %{} if and why the result should be cached.
To elaborate further, each is not a loop construct like foreach
It's more like a method operating on the hash, with no clear entry point.
Think %hash->each() and you can call each anytime outside while.
You may rather want to take a look at this newer (5.36 experimental) syntax:
use experimental "for_list"; foreach my ($key, $value) (%hash) { # iterate over the hash # The hash is immediately copied to a flat list before the loop # starts. The list contains copies of keys but aliases of values. # This is the same behaviour as for $var (%hash) {...} }
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
In reply to Re: Why does each() always re-evaluate its argument? (Updated x2 - experimental "for_list" )
by LanX
in thread Why does each() always re-evaluate its argument?
by Darkwing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |