It seems really unlikely that I've stumbled onto a Perl bug in something that's been around basically forever. But at the very best this seems to be badly misdocumented. Either that or I'm incapable of reading, which is always possible.
Here's the problem:
split 'x','x'
in list context returns a completely empty list. This happens both in 5.10 and 5.16, and, I suspect, every other version as well.
Seems to me it should be returning ('',''), since 'x' is two empty strings separated by 'x'.
Yes, I'm aware there's all sorts of strange legacy shit in split -- in particular, lots of discretion to throw out empty components when the separator pattern is matching on empty strings, or when it's the special-case " " pattern designed to be backwards compatiable with awk -- but the pattern 'x' doesn't seem to be covered by any of the weird cases and should always be doing positive-width matches.
Nor does changing it to /x/ make any difference.
And perlfunc.pod#split is also really clear that"An empty leading field is produced when there is a positive-width match at the beginning of EXPR. ...
An empty trailing field, on the other hand, is produced when there is a match at the end of EXPR, regardless of the length of the match (of course, unless a non-zero LIMIT is given explicitly, such fields are removed, as in the last example). ..."
And you'll notice above that I'm not setting any LIMITs.
So what am I missing? Where are my empty leading and trailing fields?
Is there a way to get split to return n components when there are n-1 'x's? (I already know how to do this with regexps, but it looks gross...)
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |