in reply to Re^2: Perl modifying output of an array to remove blank lines
in thread Perl modifying output of an array to remove blank lines
What is in your @Goodlines array? The code posted by stevieb seems to work exactly as advertised:
Can you put something into the @lines array that doesn't come out as you want?c:\@Work\Perl>perl -wMstrict -MData::Dump -le "my @lines = ('', ' ', ' ', 'x', ' x', 'x ', ' x ', ' x ',); ;; my @no_empties = grep { $_ !~ /^(?:\s+|)$/ } @lines; ;; dd \@no_empties; " ["x", " x", "x ", " x ", " x "]
Incidentally, I would prefer an inverse approach to the regex: a non-blank line is one that has at least one non-blank (i.e., non-whitespace, or \S) character in it:
c:\@Work\Perl>perl -wMstrict -MData::Dump -le "my @lines = ('', ' ', ' ', 'x', ' x', 'x ', ' x ', ' x ',); ;; my @no_empties = grep m{\S}xms, @lines; ;; dd \@no_empties; " ["x", " x", "x ", " x ", " x "]
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Perl modifying output of an array to remove blank lines
by hippo (Archbishop) on Oct 08, 2015 at 23:37 UTC | |
by stevieb (Canon) on Oct 08, 2015 at 23:58 UTC |