Here's a version that uses a separate array to mark when a item is used instead of building and destroying anon arrays.
#!/usr/bin/perl # http://perlmonks.org/?node_id=1186402 use strict; use warnings; my @items = qw( apple banana orange ); my @used; sub permute { @_ == @items and return print "@_\n"; $used[$_]++ || permute(@_, $items[$_]), $used[$_]-- for 0 .. $#items +; } permute();
In reply to Re^3: generating permutations
by tybalt89
in thread generating permutations
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |