in reply to How to iterate by fives?
i didn't see anything like this for chunking up the list. this way makes me warm and fuzzy...
@things = 'a'..'z'; print "#things", $/; print "@things", $/; $by = 5; print "#by", $/; print "$by", $/; @extra = ('.') x $by - 1; print "#extra", $/; print "@extra", $/; @padded_things = (@things, @extra); print "#padded_things", $/; print "@padded_things", $/; print "#chunked", $/; while ( (@chunk = splice @padded_things, 0, $by) == $by ) { print "@chunk", $/; }
$ perl test.pl #things a b c d e f g h i j k l m n o p q r s t u v w x y z #by 5 #extra . . . . #padded_things a b c d e f g h i j k l m n o p q r s t u v w x y z . . . . #chunked a b c d e f g h i j k l m n o p q r s t u v w x y z . . . .
|
|---|