NAME

Array::Extract - extract element from an array

SYNOPSIS

  use Array::Extract qw(extract);

  # remove those members from @members who are
  # blackballed and store them in @banned
  my @banned = extract { $_->blackballed } @members;

DESCRIPTION

Function to extract elements from an array that match a block. See Array::Extract::Example for a more comprehensive example of how this can be useful

Function

The function is exported on demand

extract BLOCK ARRAY

Removes elements from the ARRAY that match the block and returns them.

  # leave just the even numbers in @numbers
  my @numbers = (1..100);
  my @odds = extract { $_ % 2 } @numbers;

Care is taken to do the least number of splice operations as possible (which can be important when the array is a tied object with a class such as Tie::File)

AUTHOR

Written by Mark Fowler <mark@twoshortplanks.com>

COPYRIGHT

Copyright Mark Fowler 2011. All Rights Reserved.

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

BUGS

This module (deliberately) does not alias $_ to the actual array element within the block

Bugs should be reported via this distribution's CPAN RT queue. This can be found at https://rt.cpan.org/Dist/Display.html?Array-Extract

You can also address issues by forking this distribution on github and sending pull requests. It can be found at http://github.com/2shortplanks/Array-Extract

SEE ALSO

Array::Extract::Example List::Util, List::MoreUtils, Tie::File