This looks simple, but it's not. You can't use split to get the data, since the boundaries may be as small as one space and the data itself may contain spaces. Unpack gives errors if you try to access a position outside the string, so the last line is a major problem too. About the best you can do is the following, and it requires loading the whole set of data into memory at once to be even this neat.

EDIT: I updated my code for the wrapping text and for reading line by line instead of all at once.

use strict; use warnings; my (@col1, @col2); do {} until index(<DATA>, 'INTERESTING CODE') != -1; <DATA> for (0..1); while (<DATA>) { $_ .= ' ' x (67 - length $_); @_ = unpack 'x2A8x1A23x1A8x1A23', $_; push @col1, $_[1] if $_[0]; push @col2, $_[3] if $_[2]; } print '"' . join(', ', @col1, @col2) . '"'; __DATA__ blah blah blah blah blah blah blah blah blah blah blah blah INTERESTING CODE-- CODE NAME CODE NAME -------- ----------------------- -------- ----------------------- ABC NAME ONE RST NAME EIGHT ... DEF NAME TWO THREE WXY NAME NINE - TEN GHIJK NAME FOUR ... ZAB NAME ELEVEN LMN NAME FIVE - SIX CDE NAME TWELVE OPQ NAME SEVEN more blah blah blah

In reply to Re: Extracting formatted text block by TedPride
in thread Extracting formatted text block by punkish

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.