in reply to Bug in split?
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 )' ("", "", "", "")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bug in split?
by shawnhcorey (Friar) on Sep 27, 2017 at 14:30 UTC | |
by karlgoethebier (Abbot) on Sep 27, 2017 at 18:18 UTC | |
by afoken (Chancellor) on Sep 27, 2017 at 18:45 UTC | |
by karlgoethebier (Abbot) on Sep 27, 2017 at 19:01 UTC |