NAME

Array::Set - Perform set operations on arrays

VERSION

This document describes version 0.05 of Array::Set (from Perl distribution Array-Set), released on 2016-09-16.

SYNOPSIS

 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]

DESCRIPTION

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.

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

FUNCTIONS

All functions are not exported by default, but exportable.

set_diff([ \%opts ], \@set1, ...) => array

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").

set_symdiff([ \%opts ], \@set1, ...) => array

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_union([ \%opts ], \@set1, ...) => array

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.

set_intersect([ \%opts ], \@set1, ...) => array

Perform intersection (find elements common in all the sets). Accept optional hashref as the first argument for options. See set_diff for known options.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Array-Set.

SOURCE

Source repository is at https://github.com/perlancar/perl-Array-Set.

BUGS

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 ALSO

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.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

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.