CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [omega] cant output through perl or shell: Edit Log



FishMonger
Veteran / Moderator

Dec 16, 2012, 8:31 AM


Views: 2919
Re: [omega] cant output through perl or shell

You instructor won't accept this, but it's how I'd do it.


Code
#!/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:

Quote
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)


Edit Log:
Post edited by FishMonger (Veteran) on Dec 16, 2012, 8:32 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives