
FishMonger
Veteran
Dec 16, 2012, 8:31 AM
Views: 1194
|
|
Re: [omega] cant output through perl or shell
|
|
|
You instructor won't accept this, but it's how I'd do it.
#!/usr/bin/perl use v5.10.1; use strict; use warnings; use Algorithm::Permute; use List::Permutor; my @numbers = '01'..'04'; # extend the list as needed # method #1 Algorithm::Permute::permute { say join('-', @numbers) } @numbers; print "\n" x 3; # method #2 my $perm = List::Permutor->new(@numbers); while (my @number_set = $perm->next) { say join('-', @number_set); } This is what it outputs:
D:\test>perl-1.pl 01-02-03-04 01-02-04-03 01-04-02-03 04-01-02-03 01-03-02-04 01-03-04-02 01-04-03-02 04-01-03-02 03-01-02-04 03-01-04-02 03-04-01-02 04-03-01-02 02-01-03-04 02-01-04-03 02-04-01-03 04-02-01-03 02-03-01-04 02-03-04-01 02-04-03-01 04-02-03-01 03-02-01-04 03-02-04-01 03-04-02-01 04-03-02-01 01-02-03-04 01-02-04-03 01-03-02-04 01-03-04-02 01-04-02-03 01-04-03-02 02-01-03-04 02-01-04-03 02-03-01-04 02-03-04-01 02-04-01-03 02-04-03-01 03-01-02-04 03-01-04-02 03-02-01-04 03-02-04-01 03-04-01-02 03-04-02-01 04-01-02-03 04-01-03-02 04-02-01-03 04-02-03-01 04-03-01-02 04-03-02-01
(This post was edited by FishMonger on Dec 16, 2012, 8:32 AM)
|