ANJAN PURKAYASTHA wrote:
Hi,

Hello,

Here is my problem;
I have a series of arrays with 0s and 1s. here is an example: (1, 0, 1, 1).
I need to parse through this series of arrays and extract the index of the
0s in the array.
Is there any quick way of doing this?

$ perl -le'
my @array = ( 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1 );
print for grep $array[ $_ ] == 0, 0 .. $#array;
'
1
4
8
9


Or instead of using arrays you could store the 1s and 0s in strings:

$ perl -le'
my $string = "10110111001";
print $-[0] while $string =~ /0/g;
'
1
4
8
9


Which would probably be more efficient.



John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
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