|
List::Any - Provide the stuff missing in List::Util |
List::Any - Provide the stuff missing in List::Util
use List::Any qw(any all none notall true false firstidx lastidx);
List::Any provides some trivial but commonly needed functionality on lists
which is not going to go into List::Util.
All of the below functions are implementable in one line of Perl code. Using the functions from this module however should give slightly better performance as everything is implemented in C. The pure-Perl implementation of these functions only serves as a fallback in case the C portions of this module couldn't be compiled on this machine.
$_ for each item in LIST in turn:
print "At least one value undefined"
if any { !defined($_) } @list;
Returns false otherwise, or undef if LIST is empty.
$_ for each item in LIST in turn:
print "All items defined"
if all { defined($_) } @list;
Returns false otherwise, or undef if LIST is empty.
any. Returns a true value if no item in LIST meets the
criterion given through BLOCK. Sets $_ for each item in LIST in turn:
print "No value defined"
if none { defined($_) } @list;
Returns false otherwise, or undef if LIST is empty.
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 undef if LIST is empty.
$_ for
each item in list in turn:
printf "%i item(s) are defined", true { defined($_) } @list;
$_ for
each item in list in turn:
printf "%i item(s) are not defined", false { defined($_) } @list;
$_
for each item in list in turn:
my @list = (1, 4, 3, 2, 4, 6);
printf "item with index %i in list is 4", firstidx { $_ == 4 } @list;
__END__
item with index 1 in list is 4
Returns C<-1> if no such item could be found.
$_
for each item in list in turn:
my @list = (1, 4, 3, 2, 4, 6);
printf "item with index %i in list is 4", lastidx { $_ == 4 } @list;
__END__
item with index 4 in list is 4
Returns -1 if no such item could be found.
Bad namespace, but List::Util is already taken, quite obviously.
This is version 0.03.
Tassilo von Parseval, <tassilo.von.parseval@rwth-aachen.de>
Copyright (C) 2004 by Tassilo von Parseval
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.
|
List::Any - Provide the stuff missing in List::Util |