Array::Group(3pm)

πŸ“¦
version 4.2 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Array::Group β€” okay bestie, this one literally converts an array into an array of arrayrefs of uniform size N. That's it, that's the whole vibe. Fr fr. πŸ’…

It's a Perl module (manual page Array::Group(3pm), from the User Contributed Perl Documentation section), so if you're living in a terminal and grouping things, this is your girl. πŸŽ€


✨ SYNOPSIS ✨

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   ]
        );

Not the two of them giving completely different energy from the same input 😭 one is chunky, one is serpentine. Both iconic.


🌸 DESCRIPTION 🌸

So the ngroup method reformats a list into a list of arrayrefs. It's often used for formatting data into HTML tables, amongst other things. Lowkey the table thing is the whole reason people show up here, ngl.

dissect() on the other hand 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 β€” and bestie, this is THE tea β˜• β€” 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.

So ngroup = chop chop chop. dissect = deal the cards, one to each pile, over and over. Same list, different destiny. πŸ¦‹

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. So however your code is built, she fits. 🫢


πŸ‘‘ SEE ALSO πŸ‘‘

  • Array::Reform

πŸ’œ AUTHOR πŸ’œ

Currently maintained by Mike Accardo, <accardo@cpan.org>

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.

Not him doing the whole glow-up single-handedly 😭 ate and left no crumbs, we love to see it. πŸ’…


Copyright (c) 2015 Mike Accardo
Copyright (c) 1999-2014 Terrence Brannon

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸ’–


<span>okay that's the page!!</span> this was perl v5.36.0 energy, dated 2022-10-13, and it's Array::Group(3pm) β€” go group some arrays bestie, you got this πŸŒˆπŸ’œβ­

πŸ“¦ where this page comes from