Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I need it in one line per company (i.e. the newline between the house number and the zip code should disappear). This code does not work:__DATA__ Some Company; Some Street 52 12345 City1 Another Company; Another Street 63 23456 City2 Yet Another Company; New Street 11 34546 City3
I got something with the following workaround:use strict; use warnings; while(<DATA>) { $_=~s/([\w; ]+\d+)\n(\d{5})/$1$2/gms; print; }
but this seems ugly. Where is the catch? Many thanks! VEuse strict; use warnings; while(<DATA>) { $_=~s/(\d{5})/;$1;/g; $_=~s/\n//gms; $_=~s/(\d{5}; \w+)/$1\n/g; print; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex with Newline
by JavaFan (Canon) on Aug 26, 2011 at 16:02 UTC | |
by ricDeez (Scribe) on Aug 27, 2011 at 04:21 UTC | |
|
Re: Regex with Newline
by toolic (Bishop) on Aug 26, 2011 at 14:31 UTC | |
|
Re: Regex with Newline
by RichardK (Parson) on Aug 26, 2011 at 14:37 UTC | |
by Marshall (Canon) on Aug 26, 2011 at 16:04 UTC | |
|
Re: Regex with Newline
by hardburn (Abbot) on Aug 26, 2011 at 14:24 UTC | |
|
Re: Regex with Newline
by Anonymous Monk on Aug 26, 2011 at 14:43 UTC | |
by Marshall (Canon) on Aug 26, 2011 at 15:51 UTC |