From split (emphasis mine):

If LIMIT is negative, it is treated as if it were instead arbitrarily large; as many fields as possible are produced. If LIMIT is omitted (or, equivalently, zero), then it is usually treated as if it were instead negative but with the exception that trailing empty fields are stripped (empty leading fields are always preserved); if all fields are empty, then all fields are considered to be trailing (and are thus stripped in this case).
$ perl -E'say scalar( split( /\./, q{.}, -1 ));' 2 $ perl -E'say scalar( split( q{.}, q{.}, -1 ));' 2

Update: BTW, your two patterns are not identical:

$ perl -MData::Dump -e 'dd split( /\./, q{.x.} )' ("", "x") $ perl -MData::Dump -e 'dd split( q{.}, q{.x.} )' () $ perl -MData::Dump -e 'dd split( /\./, q{.x.}, -1 )' ("", "x", "") $ perl -MData::Dump -e 'dd split( q{.}, q{.x.}, -1 )' ("", "", "", "")

In reply to Re: Bug in split? by haukex
in thread Bug in split? by shawnhcorey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.