Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Count and print in perl

by kanikas16 (Initiate)
on Apr 20, 2017 at 06:28 UTC ( [id://1188361]=note: print w/replies, xml ) Need Help??


in reply to Re: Count and print in perl
in thread Count and print in perl

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: Count and print in perl
by kcott (Archbishop) on Apr 21, 2017 at 04:47 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1188361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-26 03:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found