1Utils(3) User Contributed Perl Documentation Utils(3)
2
3
4
6 Array::Utils - small utils for array manipulation
7
9 use Array::Utils qw(:all);
10
11 my @a = qw( a b c d );
12 my @b = qw( c d e f );
13
14 # symmetric difference
15 my @diff = array_diff(@a, @b);
16
17 # intersection
18 my @isect = intersect(@a, @b);
19
20 # unique union
21 my @unique = unique(@a, @b);
22
23 # check if arrays contain same members
24 if ( !array_diff(@a, @b) ) {
25 # do something
26 }
27
28 # get items from array @a that are not in array @b
29 my @minus = array_minus( @a, @b );
30
32 A small pure-perl module containing list manipulation routines. The
33 module emerged because I was tired to include same utility routines in
34 numerous projects.
35
37 "unique"
38 Returns an array of unique items in the arguments list.
39
40 "intersect"
41 Returns an intersection of two arrays passed as arguments, keeping
42 the order of the second parameter. A nice side effect of this
43 function can be exploited in situations as:
44
45 @atreides = qw( Leto Paul Alia 'Leto II' );
46 @mylist = qw( Alia Leto );
47 @mylist = intersect( @mylist, @atreides ); # and @mylist is ordered as Leto,Alia
48
49 "array_diff"
50 Return symmetric difference of two arrays passed as arguments.
51
52 "array_minus"
53 Returns the difference of the passed arrays A and B (only those
54 array elements that exist in A and do not exist in B). If an empty
55 array is returned, A is subset of B.
56
57 Function was proposed by Laszlo Forro <salmonix@gmail.com>.
58
60 None known yet
61
63 Sergei A. Fedorov <zmij@cpan.org>
64
65 I will be happy to have your feedback about the module.
66
68 This module is Copyright (c) 2007 Sergei A. Fedorov. All rights
69 reserved.
70
71 You may distribute under the terms of either the GNU General Public
72 License or the Artistic License, as specified in the Perl README file.
73
75 This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.
76
77
78
79perl v5.32.0 2020-07-28 Utils(3)