in reply to Melt and casting array!

( plz note: this post originally replied to a now reaped duplicate and was later reparented by the gods)

please reformat your posting:

EDIT: and please don't repost questions!!!
use strict; use warnings; my %result; # Hash of Arrays my $headline = <DATA>; # ignore while (my $line =<DATA>) { my ($gene,$sample) = split /\s+/, $line; push @{$result{$gene}},$sample; } for my $gene (sort keys %result) { print join "\t", $gene, @{$result{$gene}}; print "\n"; } __DATA__ Gene_name sample gene_A sample_1 gene_B sample_1 gene_C sample_1 gene_B sample_2 gene_C sample_2 gene_A sample_3

-->

gene_A sample_1 sample_3 gene_B sample_1 sample_2 gene_C sample_1 sample_2

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: Melt and casting array!
by perlbird (Initiate) on Apr 11, 2013 at 13:10 UTC

    wow. that's really neat and handy!

    Thanks Rolf!!