Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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 web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2016-10-22 13:18 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (294 votes). Check out past polls.