Array-Utils-0.5/0000755000175000017500000000000011370752620012241 5ustar zmijzmijArray-Utils-0.5/MANIFEST0000644000175000017500000000024111370322702013361 0ustar zmijzmijMakefile.PL MANIFEST This list of files README Changes t/array-utils.t Utils.pm META.yml Module meta-data (added by MakeMaker) Array-Utils-0.5/Makefile.PL0000644000175000017500000000057411370322702014213 0ustar zmijzmijuse ExtUtils::MakeMaker; # See ExtUtils::MakeMaker for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Array::Utils', 'VERSION_FROM' => 'Utils.pm', 'ABSTRACT_FROM' => 'Utils.pm', ($] >= 5.007003 ? ## Add these new keywords supported since 5.005 (AUTHOR => 'Sergei A. Fedorov ') : ()), ); Array-Utils-0.5/t/0000755000175000017500000000000011370752617012512 5ustar zmijzmijArray-Utils-0.5/t/array-utils.t0000755000175000017500000000273511370321351015150 0ustar zmijzmij#!/usr/bin/perl -wT use strict; use Test::More qw(no_plan); BEGIN { use_ok('Array::Utils'); } require_ok('Array::Utils'); use Array::Utils qw(:all); my @a = qw( a b c d ); my @b = qw( c d e f ); ok ( array_diff(@a, @b), "Array members comparison - different arrays" ); ok ( !array_diff(@a, @a), "Array members comparison - same array" ); my @union_ethalon = qw( a b c d e f ); my @isect_ethalon = qw( c d ); my @diff_ethalon = qw( a b e f ); my @minus_ethalon = qw( a b ); my @union = unique(@a, @b); is ( scalar(@union), 6, "Array unique union count" ); ok ( !array_diff( @union, @union_ethalon ), "Array unique union" ); my @isect = intersect(@a, @b); is( scalar(@isect), 2, "Array intersection count" ); ok ( !array_diff( @isect, @isect_ethalon ), "Array intersection" ); my @diff = array_diff(@a, @b); is ( scalar(@diff), 4, "Array symmetric difference count" ); ok ( !array_diff( @diff, @diff_ethalon), "Array symmetric difference" ); my @empty = (); ok ( array_diff( @a, @empty ), "Array diff with empty array"); ok ( array_diff( @empty, @a ), "Array diff with empty array reverse order"); ok ( !array_diff( @empty, @empty ), "Array diff with empty arrays"); my @minus = array_minus( @a, @b ); is( scalar( @minus ), 2, "Array minus count" ); ok( !array_diff( @minus, @minus_ethalon ), "Array minus" ); ok( !array_minus( @empty, @b ), "Empty array minus an array" ); @minus = array_minus( @a, @empty ); ok( !array_diff( @a, @minus ), "Substracting an empty array has no effect" ); Array-Utils-0.5/README0000644000175000017500000000024311370322702013112 0ustar zmijzmijA small pure-perl module containing list manipulation routines. See the documentation within the module for details on its use. -- Sergei A. Fedorov zmij@cpan.orgArray-Utils-0.5/META.yml0000644000175000017500000000062711370752620013517 0ustar zmijzmij--- #YAML:1.0 name: Array-Utils version: 0.5 abstract: small utils for array manipulation license: ~ author: - Sergei A. Fedorov generated_by: ExtUtils::MakeMaker version 6.42 distribution_type: module requires: meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 Array-Utils-0.5/Utils.pm0000644000175000017500000000507511370752474013715 0ustar zmijzmijpackage Array::Utils; =head1 NAME Array::Utils - small utils for array manipulation =head1 SYNOPSIS use Array::Utils qw(:all); my @a = qw( a b c d ); my @b = qw( c d e f ); # symmetric difference my @diff = array_diff(@a, @b); # intersection my @isect = intersect(@a, @b); # unique union my @unique = unique(@a, @b); # check if arrays contain same members if ( !array_diff(@a, @b) ) { # do something } # get items from array @a that are not in array @b my @minus = array_minus( @a, @b ); =head1 DESCRIPTION A small pure-perl module containing list manipulation routines. The module emerged because I was tired to include same utility routines in numerous projects. =head1 FUNCTIONS =over 4 =item C Returns an array of unique items in the arguments list. =item C Returns an intersection of two arrays passed as arguments, keeping the order of the second parameter. A nice side effect of this function can be exploited in situations as: @atreides = qw( Leto Paul Alia 'Leto II' ); @mylist = qw( Alia Leto ); @mylist = intersect( @mylist, @atreides ); # and @mylist is ordered as Leto,Alia =item C Return symmetric difference of two arrays passed as arguments. =item C Returns the difference of the passed arrays A and B (only those array elements that exist in A and do not exist in B). If an empty array is returned, A is subset of B. Function was proposed by Laszlo Forro . =back =head1 BUGS None known yet =head1 AUTHOR Sergei A. Fedorov I will be happy to have your feedback about the module. =head1 COPYRIGHT This module is Copyright (c) 2007 Sergei A. Fedorov. All rights reserved. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. =head1 WARRANTY This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND. =cut use strict; require Exporter; our @ISA = qw(Exporter); our %EXPORT_TAGS = ( all => [ qw( &unique &intersect &array_diff &array_minus ) ], ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our $VERSION = '0.5'; sub unique(@) { return keys %{ {map { $_ => undef } @_}}; } sub intersect(\@\@) { my %e = map { $_ => undef } @{$_[0]}; return grep { exists( $e{$_} ) } @{$_[1]}; } sub array_diff(\@\@) { my %e = map { $_ => undef } @{$_[1]}; return @{[ ( grep { (exists $e{$_}) ? ( delete $e{$_} ) : ( 1 ) } @{ $_[0] } ), keys %e ] }; } sub array_minus(\@\@) { my %e = map{ $_ => undef } @{$_[1]}; return grep( ! exists( $e{$_} ), @{$_[0]} ); } 1; Array-Utils-0.5/Changes0000644000175000017500000000065511370752547013552 0ustar zmijzmij=item 0.5 - May 07 2010 Cleanup unused debug modules. =item 0.4 - May 06 2010 1. Fixed memory consumption (Bug #50154). 2. Added an array_minus function (proposed by Laszlo Forro ). 3. Minor documetation changes. =item 0.3 - April 04 2007 Fix scalar context with emty arrays args =item 0.2 - March 09 2007 Removed same_members function. Optimized code. =item 0.1 - March 08 2007 First public release