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

— Ken


In reply to Re^3: Count and print in perl by kcott
in thread Count and print in perl by kanikas16

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.