in reply to How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?

G'day supriyoch_2008,

The builtin glob function handles this fine.

#!/usr/bin/env perl use strict; use warnings; use Inline::Files; my @file_data = map { [ do { local $/; <$_> } =~ /(\w+)/gm ] } *K1_TXT, *K2_TXT, + *K3_TXT; my $glob_string = join '' => map { '{' . join(',' => @$_) . '}' } @fil +e_data; print "$_\n" for glob $glob_string; __K1_TXT__ A1T1 A2T3 __K2_TXT__ C1G1 C1G2 C2G1 __K3_TXT__ A1C1

Output:

A1T1C1G1A1C1 A1T1C1G2A1C1 A1T1C2G1A1C1 A2T3C1G1A1C1 A2T3C1G2A1C1 A2T3C2G1A1C1

However, if you want to use File::Glob, this code produces the same output.

#!/usr/bin/env perl use strict; use warnings; use Inline::Files; use File::Glob qw{bsd_glob}; my @file_data = map { [ do { local $/; <$_> } =~ /(\w+)/gm ] } *K1_TXT, *K2_TXT, + *K3_TXT; my $glob_string = join '' => map { '{' . join(',' => @$_) . '}' } @fil +e_data; print "$_\n" for bsd_glob $glob_string; __K1_TXT__ A1T1 A2T3 __K2_TXT__ C1G1 C1G2 C2G1 __K3_TXT__ A1C1

I would recommend you put 'use strict;' at the top of your code and fix all the problems it highlights; including bareword in 'use File::Glob(bsd_glob);' and a plethora of undeclared variables (@array, $combi, $number, and others). I also found your code hard to read; the main problem was indentation — take a look at perlstyle.

-- Ken

  • Comment on Re: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
  • Select or Download Code