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


in reply to Re^2: split tosses away empty components even with positive width separators?
in thread split tosses away empty components even with positive width separators?

Well, one must say that the behavior shown in the following debugger session does not seem to be completely consistent.

DB<1> x split /-/, "-" empty array DB<2> x split /-/, "-foo-bar-" 0 '' 1 'foo' 2 'bar'

Replies are listed 'Best First'.
Re^4: split tosses away empty components even with positive width separators?
by AnomalousMonk (Archbishop) on May 06, 2013 at 17:42 UTC

    But see the documentation pointed out by RichardK:

    >perl -wMstrict -le "printf qq{'$_' } for split /-/, '-foo-bar-', -1; " '' 'foo' 'bar' ''

      Yeah, I had seen that point made by RichardK, but I was really referring to what is happening at the beginning of the string, which is not completely consistent. In one case you get an empty string, and in the other case you don't get it.