Thierry Vignaud > MDK-Common-1.2.30 > MDK::Common::DataStructure

Download:
MDK-Common-1.2.30.tgz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

MDK::Common::DataStructure - miscellaneous list/hash manipulation functions

SYNOPSIS ^

    use MDK::Common::DataStructure qw(:all);

EXPORTS ^

sort_numbers(LIST)

numerical sort (small numbers at beginning)

ikeys(HASH)

aka sorted integer keys, as simple as sort { $a <=> $b } keys

add2hash(HASH REF, HASH REF)

adds to the first hash the second hash if the key/value is not already there

add2hash_

adds to the first hash the second hash if the key is not already there

put_in_hash

adds to the first hash the second hash, crushing existing key/values

member(SCALAR, LIST)

is the value in the list?

invbool(SCALAR REF)

toggles the boolean value

listlength(LIST)

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"

deref(REF)

de-reference

deref_array(REF)

de-reference arrays:

    deref_array [ "a", "b" ]    #=> ("a", "b")
    deref_array "a"             #=> "a" 
is_empty_array_ref(SCALAR)

is the scalar undefined or is the array empty

is_empty_hash_ref(SCALAR)

is the scalar undefined or is the hash empty

uniq(LIST)

returns the list with no duplicates (keeping the first elements)

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" ]

difference2(ARRAY REF, ARRAY REF)

returns the first list without the element of the second list

intersection(ARRAY REF, ARRAY REF, ...)

returns the elements which are in all lists

next_val_in_array(SCALAR, ARRAY REF)

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)

group_by2(LIST)

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]

list2kv(LIST)

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]

SEE ALSO ^

MDK::Common

syntax highlighting: