in reply to Re^2: generating permutations
in thread generating permutations
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();
|
|---|