diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2008-03-17 17:19:17 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2008-03-17 17:19:17 +0000 |
commit | 969efed0bf6ffea584f378ae89ec28a89e02254f (patch) | |
tree | 1ccb72b7f95b92f4b95cd16edb3b8ceb0bf53bfe /urpm | |
parent | 9d09f8a3ec17eadf0528da3472c16454acec54ed (diff) | |
download | urpmi-969efed0bf6ffea584f378ae89ec28a89e02254f.tar urpmi-969efed0bf6ffea584f378ae89ec28a89e02254f.tar.gz urpmi-969efed0bf6ffea584f378ae89ec28a89e02254f.tar.bz2 urpmi-969efed0bf6ffea584f378ae89ec28a89e02254f.tar.xz urpmi-969efed0bf6ffea584f378ae89ec28a89e02254f.zip |
add intersection()
Diffstat (limited to 'urpm')
-rw-r--r-- | urpm/util.pm | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/urpm/util.pm b/urpm/util.pm index c6d51ea4..0af9cc53 100644 --- a/urpm/util.pm +++ b/urpm/util.pm @@ -13,7 +13,8 @@ our @EXPORT = qw(min max quotespace unquotespace same_size_and_mtime partition put_in_hash uniq uniq_ begins_with - difference2 member file_size cat_ cat_utf8 output_safe dirname basename + difference2 intersection member + file_size cat_ cat_utf8 output_safe dirname basename ); (our $VERSION) = q($Revision$) =~ /(\d+)/; @@ -137,6 +138,7 @@ sub begins_with { sub put_in_hash { my ($a, $b) = @_; while (my ($k, $v) = each %{$b || {}}) { $a->{$k} = $v } $a } sub uniq { my %l; $l{$_} = 1 foreach @_; grep { delete $l{$_} } @_ } sub difference2 { my %l; @l{@{$_[1]}} = (); grep { !exists $l{$_} } @{$_[0]} } +sub intersection { my (%l, @m); @l{@{shift @_}} = (); foreach (@_) { @m = grep { exists $l{$_} } @$_; %l = (); @l{@m} = () } keys %l } sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 } sub cat_ { my @l = map { my $F; open($F, '<', $_) ? <$F> : () } @_; wantarray() ? @l : join '', @l } sub cat_utf8 { my @l = map { my $F; open($F, '<:utf8', $_) ? <$F> : () } @_; wantarray() ? @l : join '', @l } |