summaryrefslogtreecommitdiffstats
path: root/MDK
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2002-01-27 12:38:18 +0000
committerPascal Rigaux <pixel@mandriva.com>2002-01-27 12:38:18 +0000
commitcec3bf7ceade91064ce3d87122c5aa0967e23a55 (patch)
tree181bec31e6398b1ad7f23ec5097b0da69dee1cdf /MDK
parentb3762a83bd205002bb53e7af0d1130f26c58719c (diff)
downloadperl-MDK-Common-cec3bf7ceade91064ce3d87122c5aa0967e23a55.tar
perl-MDK-Common-cec3bf7ceade91064ce3d87122c5aa0967e23a55.tar.gz
perl-MDK-Common-cec3bf7ceade91064ce3d87122c5aa0967e23a55.tar.bz2
perl-MDK-Common-cec3bf7ceade91064ce3d87122c5aa0967e23a55.tar.xz
perl-MDK-Common-cec3bf7ceade91064ce3d87122c5aa0967e23a55.zip
add MDK::Common::DataStructure::group_by2
Diffstat (limited to 'MDK')
-rw-r--r--MDK/Common/DataStructure.pm20
1 files changed, 17 insertions, 3 deletions
diff --git a/MDK/Common/DataStructure.pm b/MDK/Common/DataStructure.pm
index 83e49f1..e4b04b4 100644
--- a/MDK/Common/DataStructure.pm
+++ b/MDK/Common/DataStructure.pm
@@ -73,10 +73,15 @@ finds the value that follow the scalar in the list (circular):
C<next_val_in_array(3, [1, 2, 3])> gives C<1>
(do not use a list with duplicates)
+=item group_by2(LIST)
+
+interprets the list as an ordered hash, returns a list of [key,value]:
+C<list2kv(1 => 2, 3 => 4, 5 => 6)> gives C<[1,2], [3,4], [5,6]>
+
=item list2kv(LIST)
-interprets the list as an hash, returns the keys and the values:
-C<list2kv(1 => 2, 3 => 4)> gives C<[1,3], [2,4]>
+interprets the list as an ordered hash, returns the keys and the values:
+C<list2kv(1 => 2, 3 => 4, 5 => 6)> gives C<[1,3,5], [2,4,6]>
=back
@@ -94,7 +99,7 @@ use MDK::Common::Func;
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK);
@ISA = qw(Exporter);
-@EXPORT_OK = qw(ikeys add2hash add2hash_ put_in_hash member invbool listlength deref is_empty_array_ref is_empty_hash_ref uniq difference2 intersection next_val_in_array list2kv);
+@EXPORT_OK = qw(ikeys add2hash add2hash_ put_in_hash member invbool listlength deref is_empty_array_ref is_empty_hash_ref uniq difference2 intersection next_val_in_array group_by2 list2kv);
%EXPORT_TAGS = (all => [ @EXPORT_OK ]);
@@ -132,4 +137,13 @@ sub list2kv {
\@k, \@v;
}
+sub group_by2 {
+ my @l;
+ for (my $i = 0; $i < @_ ; $i += 2) {
+ push @l, [ $_[$i], $_[$i+1] ];
+ }
+ @l;
+}
+
+
1;