List::Extract - grep and splice combined


List-Extract documentation  | view source Contained in the List-Extract distribution.

Index


NAME

Top

List::Extract - grep and splice combined

SYNOPSIS

Top

    use List::Extract 'extract';

    my @keywords = qw/
         foo
        !bar
         baz
    /;

    my @exclude = extract { s/^!// } @keywords;

    print "Keywords: @keywords\n";
    print "Exclude: @exclude\n";

    __END__
    Keywords: foo baz
    Exclude: bar




DESCRIPTION

Top

List::Extract exports a grep-like routine called extract that both returns and extracts the elements that tests true. It's grep and splice combined.

EXPORTED FUNCTIONS

Top

Nothing is exported by default. The :ALL tag exports everything that can be exported.

$count = extract BLOCK ARRAY
@extracted = extract BLOCK ARRAY

Removes the elements from array for which BLOCK returns true. In list context the elements are returned in original order. In scalar context the number of removed elements is returned.

In BLOCK the elements in ARRAY will be accessible through $_. Modifications to $_ will be preserved in the returned list, but discarded for elements left in the array.

AUTHOR

Top

Johan Lodin <lodin@cpan.org>

COPYRIGHT

Top

SEE ALSO

Top

List::Part


List-Extract documentation  | view source Contained in the List-Extract distribution.