Array::Set - Perform set operations on arrays
This document describes version 0.05 of Array::Set (from Perl distribution Array-Set), released on 2016-09-16.
use Array::Set qw(set_diff set_symdiff set_union set_intersect); set_diff([1,2,3,4], [2,3,4,5]); # => [1] set_diff([1,2,3,4], [2,3,4,5], [3,4,5,6]); # => [1] set_diff({ignore_case=>1}, ["a","b"], ["B","c"]); # => ["a"] set_symdiff([1,2,3,4], [2,3,4,5]); # => [1,5] set_symdiff([1,2,3,4], [2,3,4,5], [3,4,5,6]); # => [1,6] set_union([1,3,2,4], [2,3,4,5]); # => [1,3,2,4,5] set_union([1,3,2,4], [2,3,4,5], [3,4,5,6]); # => [1,3,2,4,5,6] set_intersect([1,2,3,4], [2,3,4,5]); # => [2,3,4] set_intersect([1,2,3,4], [2,3,4,5], [3,4,5,6]); # => [3,4]
This module provides routines for performing set operations on arrays. Set is represented as a regular Perl array. All comparison is currently done with eq (string comparison) so currently no support for references/objects/undefs. You have to make sure that the arrays do not contain duplicates/undefs.
eq
Characteristics and differences with other similar modules:
simple functional (non-OO) interface
functions accept more than two arguments
option to do case-insensitive comparison
option to ignore blanks
preserves ordering
All functions are not exported by default, but exportable.
Perform difference (find elements in the first set not in the other sets). Accept optional hashref as the first argument for options. Known options:
ignore_case => bool (default: 0)
If set to 1, will perform case-insensitive comparison.
ignore_blanks => bool (default: 0)
If set to 1, will ignore blanks (" foo" == "foo" == "f o o").
" foo"
"foo"
"f o o"
Perform symmetric difference (find elements in the first set not in the other set, as well as elements in the other set not in the first). Accept optional hashref as the first argument for options. See set_diff for known options.
set_diff
Perform union (find elements in the first or in the other, duplicates removed). Accept optional hashref as the first argument for options. See set_diff for known options.
Perform intersection (find elements common in all the sets). Accept optional hashref as the first argument for options. See set_diff for known options.
Please visit the project's homepage at https://metacpan.org/release/Array-Set.
Source repository is at https://github.com/perlancar/perl-Array-Set.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Array-Set
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
See some benchmarks in Bencher::Scenarios::ArraySet.
App::setop to perform set operations on lines of files on the command-line.
Array::Utils, Set::Scalar, List::MoreUtils (uniq for union, singleton for symmetric diff), Set::Array, Array::AsObject, Set::Object, Set::Tiny.
uniq
singleton
perlancar <perlancar@cpan.org>
This software is copyright (c) 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Array::Set, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Array::Set
CPAN shell
perl -MCPAN -e shell install Array::Set
For more information on module installation, please visit the detailed CPAN module installation guide.