> 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;
                }
            }
        }
    }
}

Reply via email to