in reply to Joining multiple lines together while parsing
If you could show some more sample input and especially the expected output (Update: root node has been edited to include that), that would be helpful, for example I'm not sure if you want "Warning bad news here" to appear in the output.
Based on what you've provided, here's one way, using a negative lookahead to prevent the "keywords" from being interpreted as continuations.
use strict; use warnings; use Data::Dumper; local $/ = "\n\n\n"; while (<DATA>) { next unless m/Dumpdata example/; my %row = m/ ^ \s* (\w+:) \s+ ( (?: (?!^\s*\w+:) . )+ ) /xmsg; print Dumper(\%row); } __DATA__ Dumpdata example ----------------- Warning bad news here Detail: Some really nice infos these are Info: This is a problem but there is a solution
Output:
$VAR1 = { 'Detail:' => 'Some really nice infos these are ', 'Info:' => 'This is a problem but there is a solution ' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Joining multiple lines together while parsing
by Arengin (Novice) on Mar 24, 2017 at 10:28 UTC | |
by haukex (Archbishop) on Mar 24, 2017 at 10:31 UTC | |
by Arengin (Novice) on Mar 24, 2017 at 10:42 UTC | |
by haukex (Archbishop) on Mar 24, 2017 at 11:07 UTC | |
by Arengin (Novice) on Mar 24, 2017 at 11:28 UTC | |
by haukex (Archbishop) on Mar 24, 2017 at 11:33 UTC | |
by hippo (Archbishop) on Mar 24, 2017 at 11:31 UTC | |
by Arengin (Novice) on Mar 24, 2017 at 11:40 UTC |