Dear Perl Monks,

I have a very long tab separated list that looks something like this:

Apples__0.5__-10__Emma:17:15:14:18__Peter:2:7:4:1(Newline)
Pears__0.7__-12__Alex:101:144:110:111(Newline)
Oranges__0.8__-14__Shan:12:14:9:57__Heena:65:17:15:24 __Rachel:1:5:18:54(Newline)

The double underspaces represent tabs. Sorry if that comes out poorly here.

The point is that each line will have a variable amount of columns because the data from columns 3 2 onwards is variable.

I am trying to parse the list so each column after 3 has its own entry, but retaining the information that went beforehand for example:

Apples__0.5__-10__Emma:17:15:14:18(Newline)
Apples__0.5__-10__Peter:2:7:4:1(Newline)
Pears__0.7__-12__Alex:101:144:110:111(Newline)
Oranges__0.8__-14__Shan:12:14:9:57(Newline)
Oranges__0.8__-14__Heena:65:17:15:24(Newline)
Oranges__0.8__-14__Rachel:1:5:18:54(Newline)

I hope I have explained this clearly.

I tihnk this should be easy in perl but as a new perl user I am finding it difficult. My experiende is ,imited to fiddling with other already existing scripts, not writing them from scratch. (I have started doing this in excel manually but it's extremely tedious and the file is huge.)

Any help will be much appreciated.

In reply to Parsing a table with variable columns on each line by Anonymous Monk

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.