in reply to Re^2: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
in thread How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
All correct. I should have stated that I was only giving some hints rather than a functioning script.
UPDATE: The code below works hopefully and has no side effects hopefully?
use strict; use warnings; my $string = ""; my $DNA; { local $/=undef; $DNA = <DATA>; } chomp($DNA); $DNA =~ s/\n/,/g; $DNA = "{$DNA}"; $string .= $DNA; print $string; __DATA__ C1G1 C1G2 C2G1
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
by supriyoch_2008 (Monk) on Apr 24, 2013 at 19:12 UTC | |
Hi hdb, Thanks for the code snippets and update. Honestly speaking, I do not understand exactly where I have to make the changes in my script with the codes given by you in update for getting correct results from the script. I think I have to read more about the use of File::glob perl module and look for examples online to understand the stuff. Using the code given by you I have found that the cmd shows the result {C1G1,C1G2,C2G1}. I find it difficult how to use this in my script to solve the problem. With kind regards, Here goes the output of cmd:
| [reply] [d/l] |
by poj (Abbot) on Apr 24, 2013 at 20:33 UTC | |
poj | [reply] [d/l] |
by supriyoch_2008 (Monk) on Apr 25, 2013 at 03:03 UTC | |
Hi poj, Thanks for your suggestions and for showing 11 changes in my script. The script now works but in the result part, many unwanted combinations are found along with the desired 6-letter combinations. The 6-letter combinations are correct and this is only what I need in the result. How can I get only the desired 6-letter combinations in the result? Here goes the script again:
Here goes the result of cmd and of output file Joint.txt:
| [reply] [d/l] [select] |
by poj (Abbot) on Apr 25, 2013 at 07:55 UTC | |
by hdb (Monsignor) on Apr 24, 2013 at 21:15 UTC | |
The key is in the glob function. If you feed it a string like "{1,2}{a,b,c}" it creates all combinations of elements within the braces. Here is a complete solution for your problem. I hope you can adapt it to your needs. There is nothing really new in there.
So for every file you input, it creates this substring "{...,...,...}" with all elements from the file and adds it to the previous substrings of the same kind. When you are done, the overall string is fed into glob to create all combinations. I hope this makes it clear. | [reply] [d/l] |
by supriyoch_2008 (Monk) on Apr 25, 2013 at 07:17 UTC | |
Hi hdb, Thank you for the code. It works but the problem is that it produces all the combinations alongwith the desired 6-letter combinations i.e.
Here is the text output of your code:
Here the input files i.e. k1.txt, k2.txt, k3.txt are small. When the input files are large, then I shall face problem in selecting the desired longest combinations from a very large cmd or text file output. It will be much easier if the output text file shows only the longest combinations as given above. I think it is not very easy task in perl. I think so because poj has also suggested a script which produces many unwanted combinations along with the desired 6-letter longest combinations. From the output text file, the unwanted combinations are to be deleted manually to retain only the longest correct, desired combinations. It will be a very time-taking task for more input files with large size. I wish perl could solve this problem. | [reply] [d/l] [select] |
by hdb (Monsignor) on Apr 25, 2013 at 07:31 UTC | |
by supriyoch_2008 (Monk) on Apr 25, 2013 at 11:07 UTC |