The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Array::KeepGrepped - Like grep, only keeps the stuff it filters out

VERSION

version 5

SYNOPSIS

    use Array::KeepGrepped qw/kgrep/;

    my @numbers = 1..10;

    my ($even, @odd) = kgrep { $_ % 2 } @numbers;

    $, = ","; print @odd,@$even;    # prints "1,3,5,7,9,2,4,6,8,10"

DESCRIPTION

Works like the built-in Perl 'grep', but instead of just skipping over the entries that don't match, puts them instead into a seperate array that's returned (by reference) as the first item of the returned list.

Primary use for this is when you want to remove elements from an array in-place, but still be able to use what you removed.

EXAMPLES

    my @good = qw/good bad good evil good wicked good/;

    my $bad;

    ($bad, @good) = kgrep { $_ =~ /good/ } @good;

    say "@$bad | @good";   # bad evil wicked | good good good good

SEE ALSO

grep

AUTHOR

Dominic Humphries <dominic@oneandoneis2.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Dominic Humphries.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.