in reply to Extracting formatted text block

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

Replies are listed 'Best First'.
Re^2: Extracting formatted text block
by punkish (Priest) on Mar 17, 2005 at 01:30 UTC
    a'ite TedPride. You have to explain what in Larry's name you are doing here. I am not familiar with the following two idioms

    do {} until index(<DATA>, 'INTERESTING CODE') != -1; <DATA> for (0..1);
    --

    when small people start casting long shadows, it is time to go to bed