here is what I have and as I said it didn't work with the data format I am working with:

#!/usr/bin/perl use strict; use integer; my $input = shift @ARGV || 'Data.txt'; my $output = shift @ARGV || 'Output.txt'; print $input, "\n"; open(DATA,"$input") || die "cannot open $input for reading"; open(OUT, ">$output") || die "cannot open $output for writing" +; my @newcols=(); my ($genome, $id, $abd); my %phage=(); my @pg=(); my @id=(); while (my $line=<DATA>){ chomp $line; #$line =~ s/"//g; if($line =~ m/#/){ $genome = $line; push(@pg, $genome);} elsif($line !=~ m/#/){ my @cols = split(/\t/, $line); $id = $cols[0]; $abd = $cols[1]; push(@id, $id); $phage{$id}{$genome}=$abd;} #print OUT "$genome $id, $abd\n"; } my %hash = map { $_ => 1 } @id; my @unique = keys %hash; my @sorted_id = sort { ( $a <=> $b) } @unique; print OUT "\t"; for my $phagegenome(@pg){ print OUT $phagegenome, "\t"; } print OUT "\n"; for my $sorted_id(@sorted_id){ print OUT $sorted_id, "\t"; for my $pg(@pg){ print OUT "$phage{$sorted_id}{$pg}\t"; } print OUT "\n"; }

In reply to Re^2: transforming XY data to X and Multiple Y column data? by ihperlbeg
in thread transforming XY data to X and Multiple Y column data? by ihperlbeg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.