I have to do this quite often - it's actually very easy. You collect all fields as they come in into a hash and then output the fields once you've collected a complete set, just like Pokemon.
my @columns = qw( Field_1 Field_2 Field_3 ); my $flush = $columns[-1]; # maybe you have a better way of knowing whe +n your set is complete # output header: print join("\t", @columns), "\n"; my %row; while (<>) { if (/(\w+) = (.*)/) { $row{ $1 } = $2; if ($1 eq $flush) { print join("\t", @row{ @columns }),"\n"; }; } else { warn "Unknown line: $_"; next; }; };
In reply to Re: How to convert a row structured text file into a column structed text file
by Corion
in thread How to convert a row structured text file into a column structed text file
by p2perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |