Stas Bekman
Mon, 16 Jun 2003 02:10:18 -0700
Calling keys() (or values()) in void context is quite efficient.
Nice to now. So it seems the correct idiom for using each is:
keys %hash; while( my($k,$v) = each %hash ) { ... }
p.s. I've shown an example, so we can have this issue documented together with other mod_perl gotchas. It's interesting that I don't remember this issue being reported earlier.
Maybe it could be of some interest where I happened to get this problem. I got it in my custom TransHandler implemented to reduce stat calls and to obtain 'select from multiple directories' effect.
... (config file) ....
our %STATIC_FILES = ( '/img' = [ '/alternative/img', '/myapp/install/img' ], '/css' = [ '/alternative/css', '/myapp/install/css' ], ... )
... (transhandler file, simplified of course) ...
sub handler { my $r = shift; my $uri = $r->uri; ... detecting dynamic handlers ... while( my($url, $dirs) = each %STATIC_FILES ) { if( $uri =~ m{$url/(.*)$} ) { foreach my $d (@$dirs) { my $file = "$d/$1"; if( -f $file ) { $r->filename($file); return OK; } } } } }
__________________________________________________________________ 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