Scroll to navigation

SHARYANTO::List::Util(3pm) User Contributed Perl Documentation SHARYANTO::List::Util(3pm)

NAME

SHARYANTO::List::Util - List utilities

VERSION

This document describes version 0.77 of SHARYANTO::List::Util (from Perl distribution SHARYANTO-Utils), released on 2015-09-04.

FUNCTIONS

Not exported by default but exportable.

uniq_adj(@list) => LIST

Remove adjacent duplicates from list, i.e. behave more like Unix utility's uniq instead of List::MoreUtils's "uniq" function, e.g.

 my @res = uniq(1, 4, 4, 3, 1, 1, 2); # 1, 4, 3, 1, 2

uniq_adj_ci(@list) => LIST

Like "uniq_adj" except case-insensitive.

uniq_ci(@list) => LIST

Like "List::MoreUtils"' "uniq" except case-insensitive.

find_missing_nums_in_seq(LIST) => LIST

Given a list of integers, return number(s) missing in the sequence, e.g.:

 find_missing_nums_in_seq(1, 2, 3, 4, 7, 8); # (5, 6)

find_missing_strs_in_seq(LIST) => LIST

Like "find_missing_nums_in_seq", but for strings/letters "a".."z".

 find_missing_strs_in_seq("a", "e", "b"); # ("c", "d")
 find_missing_strs_in_seq("aa".."zu", "zz"); # ("zv", "zw", "zx", "zy")

min_in_range($lower, $upper, @list) => $num

Find lowest number $num in @list which still satisfies "$lower <= $num <= $upper". $lower and/or $upper can be undef to express no limit.

minstr_in_range($lower, $upper, @list) => $str

Find lowest string $str in @list which still satisfies "$lower le $x le $upper". $lower and/or $upper can be undef to express no limit.

max_in_range($lower, $upper, @list) => $num

Find highest number $num in @list which still satisfies "$lower <= $num <= $upper". $lower and/or $upper can be undef to express no limit.

maxstr_in_range($lower, $upper, @list) => $str

Find highest string $str in @list which still satisfies "$lower le $x le $upper". $lower and/or $upper can be undef to express no limit.

pick(@list) => $item

Randomly pick an item from list. It is actually simply done as:

 $_[@_ * rand]

Example:

 pick(1, 2, 3); # => 2
 pick(1, 2, 3); # => 1

pick_n($n, @list) => @picked

Randomly pick "n" different items from list. Note that there might still be duplicate values in the result if the original list contains duplicates.

 pick_n(3, 1,2,3,4,5); # => (3,2,5)
 pick_n(2, 1,2,3,4,5); # => (3,1)
 pick_n(2, 1,1,1,1);   # => (1,1)
 pick_n(4, 1,2,3);     # => (3,1,2)

SEE ALSO

SHARYANTO

HOMEPAGE

Please visit the project's homepage at <https://metacpan.org/release/SHARYANTO-Utils>.

SOURCE

Source repository is at <https://github.com/perlancar/perl-SHARYANTO-Utils>.

BUGS

Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=SHARYANTO-Utils>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2022-06-17 perl v5.34.0