BlueStarry BlueStarry - 1 year ago 65
Perl Question

Double hash entries while printing

As part of a bigger program I've got a hash. I'm testing the program printing the keys but they are all duplicates, I don't know why

while ( my $line = <SEQ> ) {

chomp $line;
$line =~ s/>//;

my ( @split1 ) = split( "\t", $line );

foreach my $chr ( keys %position ) {

#print Dumper \%position;
print "$chr\n";

foreach my $pos ( sort keys %{ $position{$chr} } ) {

if ( $split1[0] =~ /$chr/ ) {
#print "$chr\t$pos\n";

is a nested hash, when I print the keys on
print "$chr\n";
they are all doubled and I don't understand why.

The file opened on handle
looks like this:


and so on

Answer Source

Start with this:

my %data;
    my ($chr, $seq) = split;
    $data{$chr} = $seq;

print Dumper \%data;