#!/usr/bin/perl use strict; use warnings; #given a completed pentamer count file, sort pentamers, and consolidate duplicates my @data; my @currentPentLine; my $counter; my $pent; my $pentExpected; my $pentObserved; my $pentTotal; #read in input file, capturing pentamers and related info for each open(FREQ,") { chomp; @currentPentLine = split("\t", $_); $pent = $currentPentLine[0]; $pentExpected = $currentPentLine[1]; $pentObserved = $currentPentLine[2]; $pentTotal = $currentPentLine[3]; #create array of hashes with data from input file $data[$counter]{'pent'} = $pent; $data[$counter]{'count'} = $pentObserved; $data[$counter]{'prob'} = $pentExpected; $data[$counter]{'pentTotal'} = $pentTotal; $counter++; } close FREQ; my $criteria = "pent"; my @sorted_pentamers = sort { $a->{$criteria} cmp $b->{$criteria} } @data; my %totalProbability; my $probTotal; for $probTotal (@sorted_pentamers) { if (not exists $totalProbability{$probTotal->{pent}}) { $totalProbability{$probTotal->{pent}} = 0; } $totalProbability{$probTotal->{pent}} += $probTotal->{prob}; } my %totalCounts; my $countTotal; for $countTotal (@sorted_pentamers) { if (not exists $totalCounts{$countTotal->{pent}}) { $totalCounts{$countTotal->{pent}} = 0; } $totalCounts{$countTotal->{pent}} += $countTotal->{count}; } my %totalPentCounts; my $pentTotal; for $pentTotal (@sorted_pentamers) { if (not exists $totalPentCounts{$pentTotal->{pent}}) { $totalPentCounts{$pentTotal->{pent}} = 0; } $totalPentCounts{$pentTotal->{pent}} += $pentTotal->{pentTotal}; } my @keysProb = keys %totalProbability; my @keysTotal = keys %totalCounts; print @keysProb, "\n"; print @keysTotal, "\n"; #print unique sequences to output file Is there some way I could access iterate through each pentamer as a key in each of the hashes and print out each value? Thanks again!