Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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?
[stevieb]: my RPi::WiringPi now fully supports: GPIO, LCDs, digital potentiometers, analog to digital converters, shift registers, barometric pressure sensor, direct access to SPI bus, and ability for more :)
[stevieb]: ...just need to perform many tests and POD review this week, then I'm going to put together some real projects and post about them

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-01-22 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (190 votes). Check out past polls.