in reply to Re^4: Load a file into hash with duplicate keys
in thread Load a file into hash with duplicate keys

my $key = (split/\t/, $line)[0]; push @{ $hash2{$key} }, $line;
Try this instead:

my ($val, $key) = split /\t/, $line; push @{ $hash2{$key} }, $val;

Replies are listed 'Best First'.
Re^6: Load a file into hash with duplicate keys
by Anonymous Monk on Nov 02, 2010 at 21:06 UTC
    sorry, meant the other way round:

    my ($key, $val) = ...
Re^6: Load a file into hash with duplicate keys
by sophix (Sexton) on Nov 02, 2010 at 21:12 UTC

    I think you meant this:

    my ($key, $val) = split /\t/, $line; push @{ $hash2{$key} }, $val;

    In this case, it only stores the first value.

    $VAR1 = { '211560_s_at' => [ 'P' ], '204332_s_at' => [ 'P' ], '216064_s_at' => [ 'P' ], '200005_at' => [ 'P' ], '211110_s_at' => [ 'P' ], '200003_s_at' => [ 'P' ] };
      ok, then try:

      my ($key, $val) = split /\t/, $line, 2;
        Thank you, this works just fine.