Name : perl-List-Pairwise
| |
Version : 1.03
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : lp154.5.1
| Date : 2023-01-27 17:12:03
|
Group : Development/Libraries/Perl
| Source RPM : perl-List-Pairwise-1.03-lp154.5.1.src.rpm
|
Size : 0.02 MB
| |
Packager : https://www_suse_com/
| |
Summary : map/grep arrays and hashes pairwise
|
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) */!\\*
* mapp BLOCK LIST
* map_pairwise BLOCK LIST
Evaluates the BLOCK for each pair of LIST (locally setting $a and $b to each pair) and returns the list value composed of the results of each such evaluation. In scalar context, returns the total number of elements so generated (not pairs). Evaluates BLOCK in list context, so each element of LIST may produce zero, one, or more elements in the returned value.
Note that $a and $b are aliases to the list elements, so they can be used to modify the elements of the LIST, exept for hash keys ($a when LIST is a hash).
\'mapp\' is optimized in void context, and can thus be used to iterate lists pairwise.
\'map_pairwise\' is an alias for \'mapp\'.
keys/values emulation (only slower):
my AATTkeys = mapp {$a} %hash; my AATTkeys = mapp {$a} AATTlist; # same my AATTvalues = mapp {$b} %hash; my AATTvalues = mapp {$b} AATTlist; # same
copy (only slower):
my %b = mapp {$a, $b} %hash;
modify values in-place:
mapp {$b = lc($b)} %hash; mapp {$b = lc($b)} AATTlist; # same
modifying hash keys in-place does not work with a hash:
mapp {$a = lc($a)} %hash; # wrong my %b = mapp {lc($a) => $b} %hash; # ok %hash = mapp {lc($a) => $b} %hash; # also ok (copy)
modify array \"keys\" in-place does work:
mapp {$a = lc($a)} AATTlist;
modify keys and copy:
%hash = mapp {lc($a) => $b} %hash; AATThash = mapp {lc($a) => $b} AATTlist; # same
reverse hash (does not work in-place):
my %reverse_a = mapp {$b, $a} %hash;
reverse array pairs in-place:
mapp { ($a, $b) = ($b, $a) } AATTlist;
each emulation, iterating a list pairwise:
mapp { print \"$a: $b\ \"; } %hash;
mapp { print \"$a: $b\ \"; } AATTlist;
* grepp BLOCK LIST
* grep_pairwise BLOCK LIST
Evaluates the BLOCK in scalar context for each pair of LIST (locally setting $a and $b to each pair) and returns the list value consisting of those pairs for which the expression evaluated to true. In scalar context, returns the number of valid pairs, ie the number of times the expression was true.
So this equality stands:
(grepp BLOCK LIST) == 1/2 * scalar(my AATTlist = (grepp BLOCK LIST))
Note that $a and $b are aliases to the list elements, so they can be used to modify the elements of the LIST, exept for hash keys ($a when LIST is a hash).
\'grep_pairwise\' is an alias for \'grepp\'.
grep hash subset:
my %subset1 = grepp {$a =~ /^ba/} %hash; my %subset2 = grepp {$b < 5} %hash;
grep specific values:
my AATTvalues = mapp {$b} grepp {$a =~ /^ba/} %hash;
This does not work:
values grepp {$a =~ /^ba/} %hash;
values() and keys() expect a hash, whereas grepp returns a list
* firstp BLOCK LIST
* first_pairwise BLOCK LIST
Evaluates the BLOCK in scalar context for each pair of LIST (locally setting $a and $b to each pair) and returns the first pair for which the expression evaluated to true. In scalar context, returns 1 if a valid pair was found.
\'firstp\' can be used to iterate lists pairwise as does \'mapp\', but with the additional option of using the value returned by the BLOCK as a \'last\' statement
my $i; firstp { print \"$a: $b\ \"; ++$i==5 # last after 5 iterations } %hash;
* lastp BLOCK LIST
* last_pairwise BLOCK LIST
Evaluates the BLOCK in scalar context for each pair of LIST (locally setting $a and $b to each pair) and returns the last pair for which the expression evaluated to true. In scalar context, returns 1 if a valid pair was found.
* pair LIST
Returns a list of pairs as array references.
my AATTpairs = pair AATTlist; my AATTpairs = mapp {[$a, $b]} AATTlist; # same, but slower
\'pair\' can be used in combination with sort, map and grep to do ordered hash-like manipulations in long chains/streams:
my AATTranges = sort { $a->[0] < => $b->[0] or $a->[1] < => $b->[1] } grep { $_->[0] < $_->[1] } pair /\\b(\\d+)-(\\d+)\\b/g ;
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-L/15.4/noarch |