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: <%-{-{-{-<
In reply to Re^3: Perl modifying output of an array to remove blank lines
by AnomalousMonk
in thread Perl modifying output of an array to remove blank lines
by namelessjoe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |