Stas Bekman
Sun, 15 Jun 2003 18:56:30 -0700
On Sun, Jun 15, 2003 at 09:35:38PM +0200, Marcin Kasperski wrote:
Does there exist some way to protect before this problem (some kind of auto-destructor, finally, whatever which would automatically rewind the hash internal iterator while leaving the context)?
Not really a mod_perl problem, but you can read about the solution in the docs for each.
There is a single iterator for each hash, shared by all "each", "keys", and "values" function calls in the program; it can be reset by reading all the elements from the hash, or by evaluating "keys HASH" or "values HASH".
I found this note before asking, believe me... But it seems to me that this solution is not satisfactory - calling
'keys' or 'values' is inefficient and destroys most gains from
iterating over the hash using each...
Calling keys() (or values()) in void context is quite efficient.
Whether or not you appreciate the aesthetics is perhaps quite another matter.
our %hash;
%hash = map {$_ => 1 } 'a'..'c' unless %hash;for (my ($k, $v) = each %hash) {
print "$k $v\n";
last;
}__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com