Algorithm-FastPermute
view release on metacpan or search on metacpan
FastPermute.pm view on Meta::CPAN
my @array = (1..shift());
permute {
print "@array\n"; # Print all the permutations
} @array;
=head1 DESCRIPTION
Algorithm::FastPermute generates all the permutations of an array. You pass a
block of code, which will be executed for each permutation. The array will be
changed in place, and then changed back again before C<permute> returns. During
the execution of the callback, the array is read-only and you'll get an error
if you try to change its length. (You I<can> change its elements, but the
consequences are liable to confuse you and may change in future versions.)
You have to pass an array, it can't just be a list. It B<does> work with
special arrays and tied arrays, though unless you're doing something
particularly abstruse you'd be better off copying the elements into a normal
array first.
It's very fast. My tests suggest it's four or five times as fast as
Algorithm::Permute's traditional interface. If you're permuting a large list
multicall.h view on Meta::CPAN
/* In versions of perl where MULTICALL is not defined (i.e. prior
* to 5.9.4), Perl_pad_push is not exported either. It also has
* an extra argument in older versions; certainly in the 5.8 series.
* So we redefine it here.
*/
#ifndef AVf_REIFY
# ifdef SVpav_REIFY
# define AVf_REIFY SVpav_REIFY
# else
# error Neither AVf_REIFY nor SVpav_REIFY is defined
# endif
#endif
#ifndef AvFLAGS
# define AvFLAGS SvFLAGS
#endif
static void
multicall_pad_push(pTHX_ AV *padlist, int depth)
{
( run in 0.290 second using v1.01-cache-2.11-cpan-65fba6d93b7 )