On Mon, Mar 30, 2009 at 14:28, Rodrick Brown <rodrick.br...@gmail.com> wrote:
snip
> Millions of ways here is one:
snip
> my $pos = 0;
>
> for my $index (@arr) {
>  if ( $index == 0 ) {
>     printf ("%d ", $pos );
>  }
>  $pos++;
> }
snip

If you are going to go with a full bore for loop, you might as well
get rid of the index variable in the outer scope:

for my $i (0 .. $#arr) {
    push @indexes, $i if $arr[$i] == 0
}
print "@indexes\n";

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to