in reply to Perl Problems with Matching Expression Patterns

You have records with two fields seperated by colon. You can just split on that to get the arrangement you want. Putting that in a hash is attractive, but doesn't preserve order, so lets make it an array of arrays instead. You probably want to trim leading and trailing whitespace, too.

for (@DATA) { # this transforms @DATA, destructive $_ = [map {/^\s*(.*?)\s*$/} split ':', $_, 2]; }
The split on colon does the field seperation, then the mapped match trims leading and trailing space. Square brackets make the result an array reference.

To print the new @DATA in the form you want,

for (@DATA) { printf "FIRST TERM - %s\nSECOND TERM - %s\n", @$_; }

Update: holli++, I did miss that. We do see what we expect, don't we? Second try,

for (@DATA) { $_ = join ' ', split; # normalize whitespace $_ = [split /[:\s]/, $_, 2]; }
That's simpler to read, too.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Perl Problems with Matching Expression Patterns
by holli (Abbot) on Jan 12, 2005 at 21:42 UTC
    you missed the line '  fruits_vegs_food (1.0, pound);' which has no colon.