PrePAN

Sign in to PrePAN

Profile

x2Xt9yTfjgA5Q49U@github

Systems administrator new to CPAN and keen to start contributing.

GitHub: x2Xt9yTfjgA5Q49U PAUSE ID: TEJR URL: https://sanctum.geek.nz/

User's Modules

List::Breakdown Build list sublists matching conditions

EDIT: I have now added this module to CPAN: https://metacpan.org/pod/List::Breakdown

This module "breaks down" a list--filtering elements from a list into a specified bucket layout. It may be useful in situations where you have a big list of things to generate reports on or to otherwise filter into several sublists.

It differs from the excellent List::Categorize in the use of subroutine references for each category and in not requiring only one final category for any given item; an item can end up in the result set for more than one filter.

You could maybe think of this as a multi-grep that returns named results.

The synopsis code produces this structure in %filtered:

(
    all => ['foo', 'bar', 'baz', 'quux', 'wibble', 'florb'],
    has_b => ['bar', 'baz', 'wibble', 'florb'],
    has_w => ['wibble'],
    length => {
        3 => ['foo', 'bar', 'baz'],
        4 => ['quux'],
        long => ['wibble', 'florb'],
    },
    has_ba => ['bar', 'baz'],
)

The module is written and working, with a basic test suite, and can be downloaded and browsed here:

https://sanctum.geek.nz/cgit/List-Breakdown.git/

x2Xt9yTfjgA5Q49U@github 0 comments