|
NAMEList::Pairwise - map/grep arrays and hashes pairwise SYNOPSIS use List::Pairwise qw(mapp grepp);
my %hash = (
foo => 4,
bar => 2,
baz => 6,
);
my @list = %hash;
# increment values in-place
mapp {++$b} %hash;
# copy with modifications on keys
%hash = mapp {lc($a) => $b} %hash
# iterate pairwise
mapp {
print "$a: $b\n"
} %hash;
# reverse array pairs in-place
mapp { ($a, $b) = ($b, $a) } @list;
# list "keys" and "values"
my @keys = mapp {$a} @list;
my @values = mapp {$b} @list;
# grep hash subset
my %subset1 = grepp {$a =~ /^ba/} %hash;
my %subset2 = grepp {$b < 5} %hash;
DESCRIPTION"List::Pairwise" provides functions to map and grep lists two elements at a time, setting $a and $b to each pair instead of setting $_ to each element. As of version 1.01, List::Pairwise now tries to use the newly implemented XS functions pairmap, pairgrep, pairfirst and pairs from List::Util 1.31 and up, resulting in a major speedup. New code should now preferably use List::Util functions directly, with the added benefit of relying on a Perl core module. /!\ as of version 1.03 List::Pairwise does not use List::Util, because version up to the current one (1.39) presents a strange bug where a key can get undefined after an assignement (see t/listutil.t with paimap instead of mapp) /!\
EXPORTSNothing by default. Functions can be imported explicitely use List::Pairwise qw(mapp grepp first_pairwise); You can use the :all tag to import all functions, including *_pairwise aliases use List::Pairwise qw(:all); CAVEATSIn prior versions, List::Pairwise function did croak when given a list with an odd number of elements. This is not the case anymore: a warning will now be emitted if warnings of the 'misc' category are enabled, and the last pair will be completed with an undefined value. The old behavior can be restored by making these misc warnings FATAL: use warnings FATAL => 'misc'; TEST COVERAGEAs of List::Pairwise version 0.28: ---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
lib/List/Pairwise.pm 100.0 100.0 100.0 100.0 100.0 88.0 100.0
t/01load.t 100.0 n/a n/a 100.0 n/a 0.6 100.0
t/context.t 100.0 n/a n/a 100.0 n/a 0.6 100.0
t/coverage.pl 100.0 100.0 n/a 100.0 n/a 4.2 100.0
t/firstp.t 100.0 n/a n/a 100.0 n/a 1.2 100.0
t/grepp.t 100.0 n/a n/a 100.0 n/a 1.2 100.0
t/lastp.t 100.0 n/a n/a 100.0 n/a 1.2 100.0
t/mapp.t 100.0 n/a n/a 100.0 n/a 1.4 100.0
t/pair.t 100.0 n/a n/a 100.0 n/a 1.6 100.0
Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0
---------------------------- ------ ------ ------ ------ ------ ------ ------
SEE ALSOList::Util, List::MoreUtils, "grep", "map" ACKNOWLEDGMENTThe author wishes to thank:
AUTHORThomas Drugeon, <tdrugeon@cpan.org> COPYRIGHT AND LICENSECopyright (C) 2006 by Thomas Drugeon This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
|