I read some of the other postings here but didn't find anything that addresses my need. I am *very* remedial in perl but trying to learn quickly as my job description now requires it.
-I have a short script that uses List::Permutor to generate permutations of a series. Works great and prints to an outfile.
-I also have a short script that open the .txt file containing all permutations, selects unique sequences from the list, and prints the unique sequences to a new outfile.
With small series this works great, but with long series I can't complete both steps because of my computer runs out of RAM (8GB). In fact, with 12! permutations, the computer runs sluggish just to open the outfile. I thought that if I could combine the two steps to run with only 1 outfile to worry about it might save me some memory.
I have posted my code below. Thanks for your help and time!
#!/usr/bin/perl<br> use strict; use warnings; use List::Permutor; my $OutFile = '>permutations.txt'; open(OUTFILE, $OutFile) or die "The file $OutFile could not be found.\ +n"; my $word = 'aabc'; my $perm = new List::Permutor split(//,$word); while (my @set = $perm->next) { #print @set for(my $i=0; $i<length($word)-1; $i=$i+1) { my $letter = $set[$i]; print OUTFILE "$letter,"; }; my $letter = $set[length($word)-1]; print OUTFILE "$letter\n"; } close (OUTFILE);
------------------------------------------------------#!/usr/bin/perl use warnings; use strict; chdir('//Users/laptop/Desktop/') or die ("Sorry could not change to th +e perl/programs directory.\n"); my $AllPermutations = 'permutations.txt'; #INFILE open(ALLPERMUTATIONS, $AllPermutations) or die "File: $AllPermutations + failed to open: $!\n"; my $UniqPermutations = '>unique_permutations.txt'; #OUTFILE open(UNIQPERMUTATIONS, $UniqPermutations) or die "The file $UniqPermut +ations could not be found.\n"; my @AllPermutations = <ALLPERMUTATIONS>; my %seen = (); my @unique = grep { ! $seen{ $_ }++ } @AllPermutations; print "@unique"; my $str = "@unique"; print join(",",split(//,$str)); close(ALLPERMUTATIONS); close(UNIQPERMUTATIONS);
In reply to Combine Two Scripts Into One by csalzer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |