in reply to Perl modifying output of an array to remove blank lines
Welcome to the Monastery, namelessjoe,
The following will remove any lines that are empty, or contain only whitespace:
@array = grep { $_ !~ /^(?:\s+|)$/ } @array;
If you want to keep lines that do contain whitespace and nothing else (ie. remove *only* blank lines):
@array = grep { $_ ne '' } @array;
-stevieb
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl modifying output of an array to remove blank lines
by namelessjoe (Initiate) on Oct 08, 2015 at 20:00 UTC | |
by AnomalousMonk (Archbishop) on Oct 08, 2015 at 22:54 UTC | |
by hippo (Archbishop) on Oct 08, 2015 at 23:37 UTC | |
by stevieb (Canon) on Oct 08, 2015 at 23:58 UTC |