Algorithm-Loops
view release on metacpan or search on metacpan
lib/Algorithm/Loops.pm view on Meta::CPAN
my @copy= Filter( sub {s/\s/_/g}, @list );
=head3 Note on "Function BLOCK LIST" bugs
Note that in at least some versions of Perl, support for the "Filter
BLOCK ..." syntax is somewhat fragile. For example:
... Filter( {y/aeiou/UAEIO/} @list );
may give you this error:
Array found where operator expected
which can be fixed by dropping the parentheses:
... Filter {y/aeiou/UAEIO/} @list;
So if you need or want to use parentheses when calling Filter, it is best
to also include the C<sub> keyword and the comma:
lib/Algorithm/Loops.pm view on Meta::CPAN
if you write C<sub {> as part of building the list of items to be sorted
but you don't provide a comparison routine. This bug means we can't
write the previous code as:
my @sorted= Filter {
s#\d{2}(\d+)#\1#g
} sort Filter sub {
s#(\d+)# sprintf "%02d%s", length($1), $1 #g
}, @data;
because it will produce the following error:
Undefined subroutine in sort
in some versions of Perl. Some versions of Perl may even require you
to write it like this:
my @sorted= Filter {
s#\d{2}(\d+)#\1#g
} sort &Filter( sub {
s#(\d+)# sprintf "%02d%s", length($1), $1 #g
lib/Algorithm/Loops.pm view on Meta::CPAN
$iter= NestedLoops( \@Loops );
$iter= NestedLoops( \@Loops, \%Opts );
... NestedLoops( \@Loops, \%Opts, \&Code );
... NestedLoops( \@Loops, \&Code );
The "..."s above show that, when the final code reference is provided,
NestedLoops can return a few different types of information.
In a void context, NestedLoops simply iterates and calls the provided
code, discarding any values it returns. (Calling NestedLoops in a void
context without passing a final code reference is a fatal error.)
In a list context, NestedLoops C<push>es the values returned by each call
to \&Code onto an array and then returns (copies of the values from) that
array.
In a scalar contetx, NestedLoops keeps a running total of the number of
values returned by each call to \&Code and then returns this total. The
value is the same as if you had called NestedLoops in a list context and
counted the number of values returned (except for using less memory).
( run in 0.257 second using v1.01-cache-2.11-cpan-65fba6d93b7 )