In your OP, you wrote:
"I have one binary file"
I provided a solution for your "one binary file".
Now you write:
"what if i change no of bits"
Which was followed by more code not in <code> tags;
and then this demand:
"i need generlised code which work for every input given whatever it is"
This is not a code writing service.
It is not OK to just write "I need ..." and then sit back while someone does your work for you.
This site is for those who wish to learn or discuss Perl:
you need to demonstrate that you've made some effort yourself.
In the spirit of helping you to learn,
take a look at List::Util::first().
Here's an example of how you might use it to find the number you want:
$ perl -MList::Util=first -E 'my @x = qw{1 0 0 1 2 0 1 0 3 0 1 1 4 1 0
+ 0}; say first { $x[$_] == 2 } 0 .. $#x'
4
Compare that with an extract of your original data:
$ perl -MList::Util=first -E 'my @x = qw{1 1 0 0 0 0 0 0 0 0 1 0 0 0 0
+ 0 0 0 2 1 1 ...}; say first { $x[$_] == 2 } 0 .. $#x'
18
|