Hi bart,
I see what you mean now. I thought you were suggesting it would remove the newline characters, not just the blank lines. Your way is more correct.
cheers
thinker
| [reply] |
$_ = " yes \n \n \n they \n \n will \n\n\n";
s/^\s*?(?:\b(.*?)\s*?)?(\n)?$/$1$2/gm;
print;
__END__
% perl 443391.pl
yes
they
will
| [reply] [d/l] |
Danger, don't use \b if you want to detect the edges between spaces an nonspaces. It won't work for nonspace+nonword characters, like quotes and punctuation.
Perhaps replace the \b(.*?) with (\S.*?).
Still, you're not running this with warnings enabled, are you? Both $1 and $2 are optional, so both can be undef, but you use their value regardless. This runs without warnings:
s/^\s*?((?:\S.*?)?)\s*?(\n?)$/$1$2/gm;
| [reply] [d/l] |