MDK::Common::DataStructure - miscellaneous list/hash manipulation functions
use MDK::Common::DataStructure qw(:all);
numerical sort (small numbers at beginning)
aka sorted integer keys, as simple as sort { $a <=> $b } keys
sort { $a <=> $b } keys
adds to the first hash the second hash if the key/value is not already there
adds to the first hash the second hash if the key is not already there
adds to the first hash the second hash, crushing existing key/values
is the value in the list?
toggles the boolean value
returns the length of the list. Useful in list (opposed to array) context:
sub f { "a", "b" } my $l = listlength f();
whereas scalar f() would return "b"
scalar f()
de-reference
de-reference arrays:
deref_array [ "a", "b" ] #=> ("a", "b") deref_array "a" #=> "a"
is the scalar undefined or is the array empty
is the scalar undefined or is the hash empty
returns the list with no duplicates (keeping the first elements)
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" ]
returns the first list without the element of the second list
returns the elements which are in all lists
finds the value that follow the scalar in the list (circular): next_val_in_array(3, [1, 2, 3]) gives 1 (do not use a list with duplicates)
next_val_in_array(3, [1, 2, 3])
1
interprets the list as an ordered hash, returns a list of [key,value]: group_by2(1 = 2, 3 => 4, 5 => 6)> gives [1,2], [3,4], [5,6]
group_by2(1 =
[1,2], [3,4], [5,6]
interprets the list as an ordered hash, returns the keys and the values: list2kv(1 = 2, 3 => 4, 5 => 6)> gives [1,3,5], [2,4,6]
list2kv(1 =
[1,3,5], [2,4,6]
MDK::Common
To install MDK::Common, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MDK::Common
CPAN shell
perl -MCPAN -e shell install MDK::Common
For more information on module installation, please visit the detailed CPAN module installation guide.