in reply to Re: Foreach syntax
in thread Foreach syntax

I personally believe that for the benefit of the OP it would be sensible to explain that while this does exactly what he asked for: namely "select" non zero values within the C<for> clause, it would be "inefficient" (in some sense) in that grep is a loop in disguise. Thus with such code one is iterating twice over... well, not just the same list, but two strictly correlated ones. Literally, it's like one had been doing:

my @nonzero; for (keys %is_available) { push @nonzero, $_ if $is_available{$_}; } for my $p9 ( @nonzero ) { print $p9; }
--
If you can't understand the incipit, then please check the IPB Campaign.