Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Text::Table will align your output. Here is a sample program. Also, I used Sort::Naturally so that names with trailing digits will sort correctly, i.e. when they are greater than 1 digit long.

Update: in while loop, changed from split on space to split on tabs because thats how the fields are separated.

#!/usr/bin/perl use strict; use warnings; use Text::Table; use Sort::Naturally; my %data; my @col2 = qw/ PA TT AT /; while (<DATA>) { chomp; my ($name, $col2, $col3) = split /\t/; push @{ $data{$name}{$col2} }, $col3; } my $tb = Text::Table->new( map {title => $_}, @col2); for my $name (nsort keys %data) { my @tmp; local $" = ','; for my $col2 (@col2) { push @tmp, $data{$name}{$col2} ? "@{ $data{$name}{$col2} }" : ""; } $tb->load(\@tmp); } print $tb; __DATA__ Name_1 TT XL_927799.1 Name_1 PA PA_392 Name_1 AT ZX_003039195.1 Name_2 TT XL_931313.1 Name_2 AT ZX_003043016.1 Name_3 TT XL_929616.1 Name_3 PA PA_5040 Name_3 PA PA_6336 Name_4 TT XL_928294.1 Name_4 PA PA_917

This prints:

PA TT AT PA_392 XL_927799.1 ZX_003039195.1 XL_931313.1 ZX_003043016.1 PA_5040,PA_6336 XL_929616.1 PA_917 XL_928294.1

In reply to Re: reformatting tab delimited file by Cristoforo
in thread reformatting tab delimited file by garyboyd

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [Corion]: So Hyperboria is an envrypted, decentralized IPv6 mesh network. I'm interested and want to look how good coverage is in my area. But the API for querying Hyperboria is only reachable over Hyperboria itself. Thanks but no thanks.

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (3)
    As of 2017-06-23 07:25 GMT
    Find Nodes?
      Voting Booth?
      How many monitors do you use while coding?

      Results (536 votes). Check out past polls.