Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: How to I check if a value is present in an array?

by Anonymous Monk
on Aug 03, 2013 at 13:28 UTC ( #1047705=note: print w/replies, xml ) Need Help??

in reply to How to I check if a value is present in an array?

Also, you might consider another type of data-structure, such as a hash, keyed by the value of the gene-string, whose value is the number of times that this particular string occurs.   This is remarkably easy to do in Perl:

my $h={};
$h->{ $_ } ++ foreach (@my_array);

After initializing $h to an empty hashref, we loop over all elements in @my_array (each element being briefly represented by the variable $_), and increment the value of the hash-entry under that key.   Welcome to Perl’s “auto-vivication” feature:   each hash-element is magically created as necessary, and since you are “incrementing” it, the initial value automagically starts at zero.

This representation is functionally-equivalent to an array of discrete strings, but much faster to process.

  • Comment on Re: How to I check if a value is present in an array?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047705]
and the fog begins to lift...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2016-12-03 13:49 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (56 votes). Check out past polls.