Re: each considered harmful?

2003-06-16 Thread Marcin Kasperski
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

Re: each considered harmful?

2003-06-16 Thread Stas Bekman
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

Re: each considered harmful?

2003-06-16 Thread Ged Haywood
Hi guys, On Mon, 16 Jun 2003, Stas Bekman wrote: [snip,snip] keys %hash; does the trick interesting that I don't remember this issue being reported earlier. Probably because we all read the Camel Book, section 5.4.3, the bit about FIRSTKEY. All except Randal that is... :) Most people

Re: each considered harmful?

2003-06-16 Thread Stas Bekman
Ged Haywood wrote: [...] Most people when iterating over a hash will say something like foreach $scalar_name ( keys %hash_name ) { ... } which automatically resets the iterator and is safe in a perisitent Perl environment like mod_perl. I hope. That's a good point, Ged. Marcin, please include

Re: each considered harmful?

2003-06-16 Thread Randal L. Schwartz
Marcin == Marcin Kasperski [EMAIL PROTECTED] writes: Marcin Maybe it could be of some interest where I happened to get this Marcin problem. I got it in my custom TransHandler implemented to reduce stat Marcin calls and to obtain 'select from multiple directories' effect. Marcin ... (config

Re: each considered harmful?

2003-06-16 Thread Randal L. Schwartz
Randal == Randal L Schwartz [EMAIL PROTECTED] writes: Randal our @STATIC_FILES = ( Randal [ qr{^/img/(.*)$} = [ qw(/alternative/img /myapp/install/img) ], Randal [ qr{^/css/(.*)$} = [ qw(/alternative/css /myapp/install/css) ], Argh. extra left bracket snuck in. [

Re: each considered harmful?

2003-06-16 Thread Marcin Kasperski
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

Re: each considered harmful?

2003-06-16 Thread Stas Bekman
Marcin Kasperski wrote: 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

Re[2]: each considered harmful?

2003-06-16 Thread Mike P. Mikhailov
Hello Marcin Kasperski, Tuesday, June 17, 2003, 3:13:23 AM, you wrote: 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

Re: each considered harmful?

2003-06-15 Thread Randal L. Schwartz
Marcin == Marcin Kasperski [EMAIL PROTECTED] writes: Marcin You probably see the problem - when this code is re-executed (next Marcin request), the loop iterates just over 'the rest' of the hash. This is similar to the problem that shows up when you use glob in a scalar context... it also has

Re: each considered harmful?

2003-06-15 Thread Marcin Kasperski
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.

Re: each considered harmful?

2003-06-15 Thread Paul Johnson
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

Re: each considered harmful?

2003-06-15 Thread Stas Bekman
Paul Johnson wrote: 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

each considered harmful?

2003-06-14 Thread Marcin Kasperski
Hmm, probably well known but ... I have not met any direct warning of this problem so far. our %SOME_CONFIG = ( a = 1, b = 2, c = 3, ); ... while (my($k,$v) = each %SOME_CONFIG) { if( ... ) { return; # or last, or throw

Re: each considered harmful?

2003-06-14 Thread Paul Johnson
On Sat, Jun 14, 2003 at 11:33:17PM +0200, Marcin Kasperski wrote: Hmm, probably well known but ... I have not met any direct warning of this problem so far. our %SOME_CONFIG = ( a = 1, b = 2, c = 3, ); ... while (my($k,$v) = each