Hi PerlMonks,

I am interested to get the output of the following perl script (p.pl) to a text file. I have tried in several ways but I always get only the first two lines and not the actual permutations. FH does not work when I write it in between print and join. Usually FH is written between print and " and it nicely works. Here it does not. I am looking forward to perlmonks for suggestions.

Here goes the script p.pl:

#!/usr/bin/perl -l use warnings; use strict; use Algorithm::Permute; ########################################################### # Opening file to write the program's output. ################################################### open(FH, ">myPer .txt") or die "Cannot open myPer .txt"; ########################################################### my @arr = qw/A B C/; my $N=scalar(@arr); my $permu=2; my $p = new Algorithm::Permute([@arr], $permu); print"\n WELCOME to Permutation Analysis:\n All Possible Permutations of $permu Elements out of $N .i.e. $N P $pe +rmu:\n"; print FH "\n WELCOME to Permutation Analysis:\n All Possible Permutations of $permu Elements out of $N .i.e. $N P $pe +rmu:\n"; while (my(@res) = $p->next) { do {print join("", @res);};} while (my(@res) = $p->next) { do {print join("", @res);};} close FH; exit 0;

Here goes the incomplete output of text file myPer .txt:

WELCOME to Permutation Analysis: All Possible Permutations of 2 Elements out of 3 .i.e. 3 P2:

In reply to How can one get the result to a text file when print join is used? by supriyoch_2008

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.