Jens Rehsack > List-MoreUtils-0.400_002 > List::MoreUtils::Impl::Alias

Download:
List-MoreUtils-0.400_002.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

New  29
Open  26
View/Report Bugs
Module Version: 0.400_002   Source   Latest Release: List-MoreUtils-0.400_004

NAME ^

List::MoreUtils::Impl::Alias - Provide List::MoreUtils implementation by Adam Kennedy

SYNOPSIS ^

  use List::MoreUtils qw(:alias);

FUNCTIONS ^

any BLOCK LIST

Returns a true value if any item in LIST meets the criterion given through BLOCK. Sets $_ for each item in LIST in turn:

  print "At least one value undefined"
    if any { ! defined($_) } @list;

Returns false otherwise, or if LIST is empty.

The behaviour without LIST needs to be discussed!

all BLOCK LIST

Returns a true value if all items in LIST meet the criterion given through BLOCK, or if LIST is empty. Sets $_ for each item in LIST in turn:

  print "All items defined"
    if all { defined($_) } @list;

Returns false otherwise.

none BLOCK LIST

Logically the negation of any. Returns a true value if no item in LIST meets the criterion given through BLOCK, or if LIST is empty. Sets $_ for each item in LIST in turn:

  print "No value defined"
    if none { defined($_) } @list;

Returns false otherwise.

notall BLOCK LIST

Logically the negation of all. Returns a true value if not all items in LIST meet the criterion given through BLOCK. Sets $_ for each item in LIST in turn:

  print "Not all values defined"
    if notall { defined($_) } @list;

Returns false otherwise, or if LIST is empty.

sort_by BLOCK LIST

Returns the list of values sorted according to the string values returned by the KEYFUNC block or function. A typical use of this may be to sort objects according to the string value of some accessor, such as

  sort_by { $_->name } @people

The key function is called in scalar context, being passed each value in turn as both $_ and the only argument in the parameters, @_. The values are then sorted according to string comparisons on the values returned. This is equivalent to

  sort { $a->name cmp $b->name } @people

except that it guarantees the name accessor will be executed only once per value. One interesting use-case is to sort strings which may have numbers embedded in them "naturally", rather than lexically.

  sort_by { s/(\d+)/sprintf "%09d", $1/eg; $_ } @strings

This sorts strings by generating sort keys which zero-pad the embedded numbers to some level (9 digits in this case), helping to ensure the lexical sort puts them in the correct order.

nsort_by BLOCK LIST

Similar to sort_by but compares its key values numerically.

SEE ALSO ^

List::Util

AUTHOR ^

Jens Rehsack <rehsack AT cpan.org>

Adam Kennedy <adamk@cpan.org>

Tassilo von Parseval <tassilo.von.parseval@rwth-aachen.de>

COPYRIGHT AND LICENSE ^

Some parts copyright 2011 Aaron Crane.

Copyright 2004 - 2010 by Tassilo von Parseval Copyright 2013 by Jens Rehsack

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: