http://www.perlmonks.org?node_id=962383


in reply to Odd workings of split

It seems odd that, if what you want to do is to "remove newlines," that you do not use the obvious regex to do that.   If you want to "take the command up to the first newline if any," split will work fine, in a short subroutine, with an if-statement to supply an empty-string for undef.   Two (gasp!) lines of code ... problem solved.

Replies are listed 'Best First'.
Re^2: Odd workings of split
by Ralesk (Pilgrim) on Mar 29, 2012 at 13:08 UTC

    Sometimes I’m in a regexy mood and would do a lot of things with regexes — I was feeling oddly anti-regex when I wrote this and hence my preference to split’s 0th result. It’s also an… obvious way, I guess :)