Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Syntactic Confectionery Delight
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-04-23 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (554 votes), past polls