I think your regular expression here:
my %row = m/\s*(\w+)\S*\s+(\S.*)/g;
... doesn't extract everything because it's in "dot-does-not-match-newline" mode.
The /s switch makes "." match newlines ("treat variable as 's'ingle line") and thus could fix your problem:
$_ = <<DATA; Detail: Some really nice infos these are Info: This is a problem but there is a solution DATA my %row = m/\s*(\w+):\s+(\S[^:]+)/gs;
But then, that means that Info gets gobbled up again into the description part.
Personally, I would do manual line-by-line parsing instead of using one regular expression to capture everything:
$_ = <<DATA; Detail: Some really nice infos these are Info: This is a problem but there is a solution DATA my %row; my $curr; for (split /\n/) { if( /^\s*(\w+):\s+(.*)/ ) { $curr = $1; $row{ $curr } = $2; } elsif( $curr and /^\s*(.*)/ ) { $row{ $curr } .= ' ' . $1; } else { die "Unknown input data [$_]"; }; };
In reply to Re: Joining multiple lines together while parsing
by Corion
in thread Joining multiple lines together while parsing
by Arengin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |