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
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
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
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
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
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.
[
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
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
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
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
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.
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
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
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
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
15 matches
Mail list logo