summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2003-10-15 15:15:07 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2003-10-15 15:15:07 +0000
commitd7f24c815b6ee64ad2d7e0a374d593f1ecf6e301 (patch)
tree07360cc861cf9ee4036b4f58296ebc30b929746d
parentbe8f7e12a07c1f69d159516c08760b686d9d3b31 (diff)
downloadperl-MDK-Common-d7f24c815b6ee64ad2d7e0a374d593f1ecf6e301.tar
perl-MDK-Common-d7f24c815b6ee64ad2d7e0a374d593f1ecf6e301.tar.gz
perl-MDK-Common-d7f24c815b6ee64ad2d7e0a374d593f1ecf6e301.tar.bz2
perl-MDK-Common-d7f24c815b6ee64ad2d7e0a374d593f1ecf6e301.tar.xz
perl-MDK-Common-d7f24c815b6ee64ad2d7e0a374d593f1ecf6e301.zip
add uniq_ (uniq but according to some code results on each value)
-rw-r--r--MDK/Common/DataStructure.pm16
-rw-r--r--perl-MDK-Common.spec5
2 files changed, 19 insertions, 2 deletions
diff --git a/MDK/Common/DataStructure.pm b/MDK/Common/DataStructure.pm
index 195f4cb..ee649ea 100644
--- a/MDK/Common/DataStructure.pm
+++ b/MDK/Common/DataStructure.pm
@@ -72,6 +72,14 @@ is the scalar undefined or is the hash empty
returns the list with no duplicates (keeping the first elements)
+=item uniq_ { CODE } LIST
+
+returns the list with no duplicates according to the scalar results of CODE on each element of LIST (keeping the first elements)
+
+ uniq_ { $_->[1] } [ 1, "fo" ], [ 2, "fob" ], [ 3, "fo" ], [ 4, "bar" ]
+
+gives [ 1, "fo" ], [ 2, "fob" ], [ 4, "bar" ]
+
=item difference2(ARRAY REF, ARRAY REF)
returns the first list without the element of the second list
@@ -111,7 +119,7 @@ use MDK::Common::Func;
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK);
@ISA = qw(Exporter);
-@EXPORT_OK = qw(sort_numbers ikeys add2hash add2hash_ put_in_hash member invbool listlength deref deref_array is_empty_array_ref is_empty_hash_ref uniq difference2 intersection next_val_in_array group_by2 list2kv);
+@EXPORT_OK = qw(sort_numbers ikeys add2hash add2hash_ put_in_hash member invbool listlength deref deref_array is_empty_array_ref is_empty_hash_ref uniq uniq_ difference2 intersection next_val_in_array group_by2 list2kv);
%EXPORT_TAGS = (all => [ @EXPORT_OK ]);
@@ -134,6 +142,12 @@ 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 uniq_(&@) {
+ my $f = shift;
+ $l{$f->($_)} = 1 foreach @_;
+ grep { delete $l{$f->($_)} } @_;
+}
+
sub next_val_in_array {
my ($v, $l) = @_;
diff --git a/perl-MDK-Common.spec b/perl-MDK-Common.spec
index d2e8684..c18843e 100644
--- a/perl-MDK-Common.spec
+++ b/perl-MDK-Common.spec
@@ -2,7 +2,7 @@
# do not change the version here, change in MDK/Common.pm.pl
%define version THEVERSION
-%define release 1mdk
+%define release 2mdk
%ifarch x86_64
%define build_option PERL_CHECKER_TARGET='debug-code BCSUFFIX=""'
@@ -72,6 +72,9 @@ rm -rf $RPM_BUILD_ROOT
# MODIFY IN THE CVS: cvs.mandrakesoft.com:/cooker soft/perl-MDK-Common
%changelog
+* Wed Oct 15 2003 Guillaume Cottenceau <gc@mandrakesoft.com> 1.1.7-2mdk
+- add uniq_ (uniq but according to some code results on each value)
+
* Fri Sep 19 2003 Pixel <pixel@mandrakesoft.com> 1.1.7-1mdk
- read_gnomekderc() & update_gnomekderc() will now handle key=value where key
can contain spaces