"How can I find all the permutations of a list (or a word)"? I have seen this question asked a number of times on forums. There is a module that makes this task very easy: List::Permutor. It is not a core module so you may need to install it. See module for more details: List::Permutor
Process all possible permutations of a list
# permutations of an array:
use List::Permutor;
my @array = qw(Mary had a little lamb);
my $perm = new List::Permutor @array;
while (my @set = $perm->next) {
print "One order is @set.\n";
}
# permutations of a word:
use List::Permutor;
my $word = 'perl';
my $perm = new List::Permutor split(//,$word);
while (my @set = $perm->next) {
print "One order is @set.\n";
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.