http://www.perlmonks.org?node_id=861947


in reply to Rosetta code: Split an array into chunks

A solution that'll be hard to map to a different language (except perhaps Perl6):
sub TIESCALAR{bless[0,$_[1]],$_[0]} sub FETCH{${$_[0]}[0]++%${$_[0]}[1]?" ":"\n"}; sub chunk_array{tie local$",'main',shift;"@_\n";}