g_speran has asked for the wisdom of the Perl Monks concerning the following question:
using perl substitution (s/ / /g;) how can I make the contents become like the followingline1 line2 line4 line6
I have tried $_ =~ s/\n\n+/\n/g; but that is not working for me. Below is the code I am working withline1 line2 line4 line6
TIA....open(FILE, "<$MODFILE") || die "File not found"; my @lines = <FILE>; close(FILE); my @newlines; foreach(@lines) { $_ =~ s/\n\n+/\n/g; push(@newlines,$_); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: replace multiple newline characters
by Marshall (Canon) on May 15, 2018 at 04:25 UTC | |
|
Re: replace multiple newline characters
by AnomalousMonk (Archbishop) on May 15, 2018 at 03:43 UTC | |
|
Re: replace multiple newline characters
by haukex (Archbishop) on May 15, 2018 at 04:30 UTC | |
|
Re: replace multiple newline characters
by morgon (Priest) on May 15, 2018 at 07:58 UTC | |
by hippo (Archbishop) on May 15, 2018 at 08:15 UTC | |
by haukex (Archbishop) on May 15, 2018 at 09:48 UTC | |
by hippo (Archbishop) on May 15, 2018 at 09:59 UTC | |
by haukex (Archbishop) on May 15, 2018 at 10:07 UTC | |
|
Re: replace multiple newline characters
by thanos1983 (Parson) on May 15, 2018 at 09:37 UTC |