Util::Medley::List - utility methods for working with lists
version 0.060
%map = $util->listToMap(@list); %map = $util->listToMap(list => \@list); $min = $util->min(@list); $min = $util->min(list => \@list); $max = $util->max(@list); $max = $util->max(list => \@list); @list = $util->undefsToStrings(@list); @list = $util->undefsToStrings(list => \@list); @uniq = $util->uniq@list); @uniq = $util->uniq(list => \@list);
...
Search for pattern in a list.
Returns bool
$bool = $util->contains(\@list, 'mystring'); $bool = $util->contains(\@list, undef); $bool = $util->contains(\@list, qr/myregex/); $bool = $util->contains(list => \@list, match => 'mystring'); $bool = $util->contains(list => \@list, match => undef); $bool = $util->contains(list => \@list, match => qr/myregex/);;
An array of values.
Pattern to search for. This can be a string, regex, or undef.
Returns an array of elements that are found in list1 or list2, but not both.
Wrapper around List::Compare::get_symmetric_difference().
@diff = $util->diff(\@list1, \@list2, $sort); @diff = $util->diff(list1 => \@list1, list2 => \@list2, sort => $sort);
The first array.
The second array.
Flag to enable/disable pre-sorting. This leverages the nsort method, within this class, rather than Perl's sort routine.
Default is 1.
Compares two arrays and returns true if they differ or false if not.
$bool = $util->differ(\@list1, \@list2, $sort); $bool = $util->diff(list1 => \@list1, list2 => \@list2, sort => $sort);
Checks if the scalar value passed in is an array.
$bool = $util->isArray(\@a); $bool = $util->listToMap(ref => \@a);
The scalar value you wish to check.
%map = $util->listToMap(@list); %map = $util->listToMap(list => \@list);
The array you wish to convert to a hashmap.
Just a passthrough to List::Util::min()
$min = $util->min(@list); $min = $util->min(list => \@list);
Just a passthrough to List::Util::max()
$max = $util->max(@list); $max = $util->max(list => \@list);
Sort an array naturally (case in-sensitive). This behaves the same way Sort::Naturally::nsort does with the exception of using fc (casefolding) instead of lc (lowercase). This guarantees the same results without regard to locale (which Sort::Naturally::nsort does use).
@sorted = $util->nsort(@list); @sorted = $util->nsort(list => \@list);
The list to act on.
Just a passthrough to List::Util::shuffle()
$max = $util->shuffle(@list); $max = $util->shuffle(list => \@list);
%map = $util->undefsToStrings($list, [$string]); %map = $util->undefsToStrings(list => \@list, [string => $str]);
What to convert undef items to. Default is empty string ''.
Just a proxy to List::Util::uniq().
@uniq = $util->uniq(@list); @uniq = $util->uniq(list => \@list);
To install Util::Medley, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Util::Medley
CPAN shell
perl -MCPAN -e shell install Util::Medley
For more information on module installation, please visit the detailed CPAN module installation guide.