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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |