|
|
On Oct 19, 6:38 am, sisyphus...@xxxxxxxxx (Sisyphus) wrote:
> On Oct 17, 3:04 am, sharan.basa...@xxxxxxxxx (Sharan Basappa) wrote:
> .
> .
>
>
>
> > #!/usr/bin/perl
> > use warnings;
> > use Algorithm::Permute;
> > my @array = (1..4);
> > Algorithm::Permute::permute { print "@array\n" } @array;
>
> use warnings;
> use strict;
> use Algorithm::Permute;
>
> my @array = (1..9);
> my $p = new Algorithm::Permute(\@array);
>
> # print out the first 20 permutations of @array,
> # assigning each permutation to @new, and
> # printing it out:
> for(1..20) {
> my @new = $p->next;
> print "@new\n";
>
> }
>
> Cheers,
> Rob
Thanks, Rob
I have modified the code a little bit to suit my requirements. But
still the code does not seem to work i.e.
the final print of @x does not display any value. However, I change
the code foreach (@array) to for (1..)
the way you have coded, it works fine. My requirement is to put all
the permutations into a new array,
not just (1..20)
I have another basic doubt. After permute is called with @array
argument, does it now contain
new permutations or still (1..4).
#!/usr/bin/perl
use warnings;
use Algorithm::Permute;
my @array = (1..4);
my $p = new Algorithm::Permute(\@array);
foreach (@array)
{
my @x = $p->next;
print "@x \n";
}
Regards
|
|