Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The lines with parenthesis at the end are to become the titels, the other lines should be linked to these titels this way:Titel Text (A12-3) 3-123.7 Just another text 3-123.8 Some more text A12.34 Another item B56.78 Yet another item Another Titel Text (B23-9) 1-22a.b Just another text 2-3cd.e Some more text W12.34 Another item Z56.78 Yet another item
As you see some the "other lines" should begin with the certain pattern, sometimes they do not and build a single line. I tried to break these lines with a newline character in the following way (thanks to toolic and Marschall since I used some fragments from their earlier advices) but the actual script seems to ignore the added newline.Titel Text (A12-3);3-123.7 Just another text Titel Text (A12-3);3-123.8 Some more text Titel Text (A12-3);A12.34 Another item Titel Text (A12-3);B56.78 Yet another item
Where do I make the mistake(s)? I work on Win32 with ActivePerl distribution. Thank you very much in advance! VEuse strict; use warnings; my $outcome; my $previous; while(<DATA>) { $outcome = ""; chomp; $_=~ s/\s(\d\-\d\w{2}(\.\w+)?)/\n$1/g; $_=~ s/\s([A-Z]\d{2}(\.\d+)?)/\n$1/g; if (/\s?\d\-\d\w{2}(\.\w+)?.+|\s?[A-Z]\d{2}(\.\d+)?.+|\(\w+\-\ +d+\)$/) { if (/\(\w+\-\d+\)$/ ) { $previous = $_; } else { $outcome = "$previous;$_"; } $outcome=~s/^\s+$//g; print "$outcome\n"; } } __DATA__ Titel Text (A12-3) 3-123.7 Just another text 3-123.8 Some more text A12.34 Another item B56.78 Yet another item Another Titel Text (B23-9) 1-22a.b Just another text 2-3cd.e Some more text W12.34 Another item Z56.78 Yet another item Some trash Some trash
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Insert newline
by thewebsi (Scribe) on Sep 14, 2011 at 17:41 UTC | |
by Anonymous Monk on Sep 14, 2011 at 18:17 UTC | |
|
Re: Insert newline
by wwe (Friar) on Sep 14, 2011 at 15:37 UTC | |
by Anonymous Monk on Sep 14, 2011 at 17:10 UTC | |
|
Re: Insert newline
by Not_a_Number (Prior) on Sep 14, 2011 at 18:50 UTC | |
by Anonymous Monk on Sep 15, 2011 at 14:48 UTC | |
by Not_a_Number (Prior) on Sep 15, 2011 at 18:07 UTC | |
by Anonymous Monk on Sep 15, 2011 at 19:37 UTC | |
by vagabonding electron (Curate) on Sep 16, 2011 at 13:22 UTC | |
|
Re: Insert newline
by pvaldes (Chaplain) on Sep 14, 2011 at 18:38 UTC |