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!


FIRST
---------------------
#!/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);

-----------------------------------------

SECOND
-----------------------

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.