Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
Please login to access the resource
devel:languages:perl:CPAN-L
perl-List-Pairwise
perl-List-Pairwise.spec
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File perl-List-Pairwise.spec of Package perl-List-Pairwise
# # spec file for package perl-List-Pairwise # # Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # Please submit bugfixes or comments via https://bugs.opensuse.org/ # Name: perl-List-Pairwise Version: 1.03 Release: 0 %define cpan_name List-Pairwise Summary: Map/grep arrays and hashes pairwise License: Artistic-1.0 OR GPL-1.0-or-later Group: Development/Libraries/Perl Url: https://metacpan.org/release/%{cpan_name} Source0: https://cpan.metacpan.org/authors/id/T/TD/TDRUGEON/%{cpan_name}-%{version}.tar.gz BuildArch: noarch BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: perl BuildRequires: perl-macros %{perl_requires} %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 @keys = mapp {$a} %hash; my @keys = mapp {$a} @list; # same my @values = mapp {$b} %hash; my @values = mapp {$b} @list; # same copy (only slower): my %b = mapp {$a, $b} %hash; modify values in-place: mapp {$b = lc($b)} %hash; mapp {$b = lc($b)} @list; # 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)} @list; modify keys and copy: %hash = mapp {lc($a) => $b} %hash; @hash = mapp {lc($a) => $b} @list; # 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) } @list; each emulation, iterating a list pairwise: mapp { print "$a: $b\n"; } %hash; mapp { print "$a: $b\n"; } @list; * 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 @list = (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 @values = 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\n"; ++$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 @pairs = pair @list; my @pairs = mapp {[$a, $b]} @list; # 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 @ranges = sort { $a->[0] <=> $b->[0] or $a->[1] <=> $b->[1] } grep { $_->[0] < $_->[1] } pair /\b(\d+)-(\d+)\b/g ; %prep %setup -q -n %{cpan_name}-%{version} find . -type f ! -name \*.pl -print0 | xargs -0 chmod 644 %build PERL_USE_UNSAFE_INC=1 perl Makefile.PL INSTALLDIRS=vendor make %{?_smp_mflags} %check make test %install %perl_make_install %perl_process_packlist %perl_gen_filelist %files -f %{name}.files %defattr(-,root,root,755) %doc Changelog %changelog
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor