I found locally the following perl code that calculates all possible combinations for chars or numbers but you need to provide them using a qw function my @strings = [qw(1 2 3 4 5 6 7 8 9 10 11 12 13)];, and I need to read these numbers (1 2 3 4 5 6 7 8 9 10 11 12 13) from a file and pass them to the @strings array or pass the numbers via Perl line command arguments to the mentioned @strings array.
I've read all info regarding qw() but I didn't find a way to use it when reading a file of Perl line command arguments, so can you give some advice in order to fix this issue?.
The output provided now is:
1 2 3 4 5
1 2 3 4 6
1 2 3 4 7 ...
Code:
use strict;
use warnings;
#my $strings = [qw(AAA BBB CCC DDD EEE)];
#my $strings = [qw(1 2 3 4 5 6 7 8 9 10 11 12 13)];
my @strings = [qw(1 2 3 4 5 6 7 8 9 10 11 12 13)];
sub combine;
print "@$_\n" for combine @strings, 5;
sub combine {
my ($list, $n) = @_;
die "Insufficient list members" if $n > @$list;
return map [$_], @$list if $n <= 1;
my @comb;
for (my $i = 0; $i+$n <= @$list; ++$i) {
my $val = $list->[$i];
my @rest = @$list[$i+1..$#$list];
push @comb, [$val, @$_] for combine \@rest, $n-1;
}
return @comb;
}