in reply to map {} list or do {} for list?
IIRC old versions of Perl had limitations with map in void context, but that's history.
Some might argue that this is more readable
for my $key ( keys %hosts ) { if ( $hosts{$key} != $table_count ) { delete $hosts{$key}; } }
Cheers Rolf
( addicted to the Perl Programming Language)
inverted unless to if
while ( my ($key,$value) = each %hosts) { delete $hosts{$key} if $value != $table_count; }
but I'm not sure about side effects!
aha -> each
If you add or delete elements of a hash while
you’re iterating over it, you may get entries skipped or
duplicated, so don’t. Exception: It is always safe to delete
the item most recently returned by "each()", which means that
the following code will work:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: map {} list or do {} for list?
by McA (Priest) on Apr 11, 2014 at 14:58 UTC | |
by LanX (Saint) on Apr 11, 2014 at 15:14 UTC | |
by choroba (Cardinal) on Apr 11, 2014 at 15:17 UTC | |
by LanX (Saint) on Apr 11, 2014 at 15:20 UTC | |
|
Re^2: map {} list or do {} for list?
by McA (Priest) on Apr 11, 2014 at 14:35 UTC |