in reply to Using hash keys to separate data
And for the rest, as wfsp already said: push the data onto the anonymous array which comprise the values of the hash (autovivified, so don't worry about the anonymous array not existing).
After that it's just a matter of looping through the keys, and print out the contents of the array.while (<REG>) { chomp; my($key, $data) = split "\t", $_, 2; push @{$R{$key}}, $data; }
foreach my $key (keys %R) { open my $fh, '>', "$key.out" or die "Cannot open file $key.out: $! +"; foreach my $row (@{$R{$key}}) { print $fh "$key\t$row\n"; } }
|
|---|