Array::Group(3pm)

Array::Group3pm

Convert an array into array of arrayrefs of uniform size n.

Usage

  use Array::Group qw( :all );
  @sample = ( 1 .. 10 );
  $rowsize = 3;
  ngroup $rowsize => \@sample ;
  # yields
         (
            [   1,   2,   3   ],
            [   4,   5,   6   ],
            [   7,   8,   9   ],
            [   10   ]
          );
  dissect $rowsize => \@sample ;
  # yields
         (
            [   1,   5,   9   ],
            [   2,   6,  10   ],
            [   3,   7   ],
            [   4,   8   ]
          );

Overview

The "ngroup" method reformats a list into a list of arrayrefs. It is often used for formatting data into HTML tables, amongst other things.

"dissect()" returns a list of lists where the first element of each sublist will be one of the first elements of the source list, and the last element will be one of the last. This behaviour is much more useful when the input list is sorted.

The key difference between the two methods is that "dissect()" takes elements from the start of the list provided and pushes them onto each of the subarrays sequentially, rather than simply dividing the list into discrete chunks.

Both methods can be called as either functions or class methods (to ensure compatibility with previous releases), and the array to be reformed can be passed as a reference.

Releases

6 releases since Debian 8 (Jessie); the text changed 2 times.

  1. 8
  2. 9–11
  3. 12–13

Author

Currently maintained by Mike Accardo, <[email protected]>

Original author Terrence Monroe Brannon.

Contributors

I would like to thank Alexandr Ciornii for his help in upgrading this distribution's format. He took me from using a test.pl file to using the t/ directory and removed some old crufty things that were not needed. He also upgraded the Makefile.PL.

From libarray-group-perl 4.2-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.