Marcin Kasperski wrote:
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 ) {
        ...
   }

Looks like it. probably with a comment so you (or other readers) won't forget why you did that.


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

ah, a real-world example. Just what we need. Care to write a short pod section using this example, explaining the problem and the solution? plain text or pod will do. we will add it to the coding chapter.


Thanks.

__________________________________________________________________
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



Reply via email to