in reply to Foreach syntax
If you want it all on one line:
for my $p9 ( grep { $is_available{$_} } keys %is_available ) {
If you want it efficient:
for my $p9 ( keys %is_available ) { next if ! $is_available( $p9 };
Which one of those is faster will probably depend on how many items get filtered out for looping. The grep is a loop in itself, so that solution actually loops twice with the second loop being "shorter"—depending on how many are filtered out. I expect grep to be a faster loop than the for, however, so that might still be a speed increase—depending on how many are filtered out.
All that's more or less irrelevant, however, until profiling your code shows that this is an issue. There's no need to make it faster until you're sure it's what's slowing you down.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Foreach syntax
by chromatic (Archbishop) on Jul 26, 2008 at 05:35 UTC | |
by BrowserUk (Patriarch) on Jul 26, 2008 at 07:49 UTC |