If I'm understanding you correctly, you could just collect things in a hash, keyed by the first column:

my %rows; while (<DATA>) { my ($key, $c1, $c2, $c3) = split; push @{ $rows{$key} }, "${c1}_$c2,$c3"; } for my $key (keys %rows) { print join("\t", $key, @{ $rows{$key} }), "\n"; } __DATA__ frog-n as novelty-n 5.8504 frog-n be yellow-n 6.1961 frog-n be-1 Asia-n 5.0937 frog-n coord zebra-n 5.9279 frog-n coord-1 Canuck-n 6.3363 frog-n nmod-1 mule-n 4.2881 amphibian-n success-1 surprising-j 14.6340 amphibian-n such_as alligator-n 11.5265 amphibian-n than work-n 5.9948 amphibian-n though stalk-n 13.2228

Output:

frog-n as_novelty-n,5.8504 be_yellow-n,6.1961 be-1_Asia-n,5. +0937 coord_zebra-n,5.9279 coord-1_Canuck-n,6.3363 nmod-1_mule +-n,4.2881 amphibian-n success-1_surprising-j,14.6340 such_as_alligator-n,11 +.5265 than_work-n,5.9948 though_stalk-n,13.2228

(Note that the rows in the unsorted hash printout are only "by accident" in the same order the keys occurred the input data.  In case ordering matters, you'd need to take care of it separately (e.g. using Tie::IxHash).)


In reply to Re: Problems with complex structure and array of arrays by Eliya
in thread Problems with complex structure and array of arrays by remluvr

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.