Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: finding matches in the same array

by salva (Canon)
on Apr 14, 2005 at 22:19 UTC ( [id://447991]=note: print w/replies, xml ) Need Help??


in reply to finding matches in the same array

use two hashes, one for totals an other for counters, them use two loops, one to populate these hashes and other to calculate the averages as total/counter:
my @sequence = ('actg','actg','cggt','cggt'); my @numbers = ('1234','2345','3244','3455'); my (%total, %count, $i); for ($i=0; $i<@sequence; $i++) { $total{$sequence[$i]}+=$numbers[$i]; $count{$sequence[$i]}++; } for (sort keys %total) { my $avg=$total{$_}/$count{$_}; print "$_ avg: $avg\n"; }

Log In?
Username:
Password:

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

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

    No recent polls found