$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 ;)
In reply to Re: discussion: What should split( /PATTERN/, EXPR, 0 ) return better? (LIMIT is consistent! )
by LanX
in thread discussion: What should split( /PATTERN/, EXPR, 0 ) return better?
by rsFalse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |