in reply to discussion: What should split( /PATTERN/, EXPR, 0 ) return better?
$sum += $_ for split ' ', "5 6 7 8\n", $K;
is broken! *
Because split will always also return the unsplitted remaining rest which of course can't be added.
DB<20> use Data::Dump qw/dd/; DB<21> $str = join " ", 10..15 DB<22> dd ["$_",( split ' ', $str, $_)] for 0..6 [0, 10 .. 15] [1, "10 11 12 13 14 15"] [2, 10, "11 12 13 14 15"] [3, 10, 11, "12 13 14 15"] [4, 10, 11, 12, "13 14 15"] [5, 10 .. 13, "14 15"] [6, 10 .. 15]
and your desired count behavior for LIMIT=0 is actually mapped on LIMIT=1
In other words LIMIT may have a complicated design, but it's consistent.
see my other post Re: discussion: What should split( /PATTERN/, EXPR, 0 ) return better? (split-LIMIT = count and/or flag) for a working example.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
*) tybalt89's hint was maybe a bit too subtle ;)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: discussion: What should split( /PATTERN/, EXPR, 0 ) return better? (LIMIT is consistent! )
by rsFalse (Chaplain) on Oct 13, 2017 at 10:52 UTC | |
by LanX (Saint) on Oct 13, 2017 at 13:06 UTC | |
by rsFalse (Chaplain) on Oct 13, 2017 at 13:14 UTC | |
by LanX (Saint) on Oct 13, 2017 at 14:26 UTC | |
by rsFalse (Chaplain) on Oct 13, 2017 at 19:11 UTC |