in reply to Re: Rosetta code: Split an array into chunks
in thread Rosetta code: Split an array into chunks
my take on it
use strict; use warnings; use Test::More; sub chunks { my ( @list ) = @_ ; my $count = 3; my $str = ""; while (my @cols = splice @list, 0, $count ) { $str .= "@cols\n"; } return $str; } # ========= Tests is( chunks("a", "bb", "c", "d", "e", "f", "g", "h") => <<'__CHUNK__', "Rosetta's Example" ); a bb c d e f g h __CHUNK__ is( chunks() => "", "Empty" ); done_testing;
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Rosetta code: Split an array into chunks
by LanX (Saint) on Oct 22, 2021 at 17:45 UTC | |
Re^3: Rosetta code: Split an array into chunks
by tybalt89 (Monsignor) on Oct 22, 2021 at 17:57 UTC | |
by LanX (Saint) on Oct 22, 2021 at 18:01 UTC |