in reply to Creating hash: Key is unique string in array element, value is number of times it appears

If you want to accumulate all your data into one hash, you need to declare it outside the while loop:
use warnings; use strict; use Data::Dumper; my %genus; while ( my $line = <DATA> ) { chomp $line; next if $line =~ /Query=/; my @hit = split( /\s/, $line ); $genus{ $hit[2] }++; } print Dumper(\%genus); __DATA__ Query= 16sV5:44:FC62N5DAAXX:7:1:18808:1248 1:N:0: 1111599 AB563244.1 Streptococcus macedonicus str. W28 1111215 AB563262.1 Streptococcus equinus str. MTS6
prints...
$VAR1 = { 'Streptococcus' => 2 };
  • Comment on Re: Creating hash: Key is unique string in array element, value is number of times it appears
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Creating hash: Key is unique string in array element, value is number of times it appears
by putmant (Initiate) on Oct 26, 2011 at 17:26 UTC

    Thank you so much! This worked perfect. Thanks to the other repilers as well