You need to either a) open your file before the foreach loop, or b) open the
file in append mode.  When you use this line, "open(OUT,
'>outputfile.txt')", Perl opens the file and removes the contents.  It
truncates the file to 0 bytes.  This is because you are using the > operator
instead of the >> operator.  It would be better to open the file outside the
loop, however so that you don't open and close the file every time you go
through the loop.

-----Original Message-----
From: Nandita Mullapudi [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 09, 2002 9:49 AM
To: [EMAIL PROTECTED]
Subject: printing output to a file


hello list
i am trying to print the output of a parsing script to a file- the way it
is right now, the print commands are within a foreach loop, and it prints
to the screen. in order to get the entire output into a file, i'm using a
simple set of commands like so:

        foreach my $key (keys %alignments) {
    print "$key\nXXXXXXXXXXXX\n", $alignments{$key}, "\nXXXXXXXXXXX\n";

    open (OUT, '>outputfile.txt') or die "couldn't";
    print OUT "$key\nXXXXXXXXXXXX\n", $alignments{$key}, "\nXXXXXXXXXXX\n"
}

print $ending_annotation;
exit;

the output to the screen prints the entire output correctly, but when i
open the file output.txt i get only the last item in my output, not the
entire list..

any help appreciated..

many thanks
nandita.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to