Hi, I'm new to this forum. I have a question regarding outputting to .txt file.

while($file =<DNAFILE>)
{
    open FILE, ">newseq.txt";
my $dna = fasta($file);
my $newseq = mutationdna($dna,$years);
print FILE $newseq; #this does not work. how do I fix it?
print $newseq; # this work
}

The outputting to newseq.txt file does not work. There are no sequences in the file. However, if i just print of $newseq directly on the screen, I can see the mutated DNA sequence in the terminal.
Howe do I fix this so the mutated new sequence will be outputted to a txt file? Thanks for the help

open FILE, ">newseq.txt";

The above line must create "newseq.txt". Suppose the end of the process $newseq should 'null' value, at the time newseq.txt will be a blank file. To avoid this kind of circumstance, the file declaration line should be occurred at before the loop.

you will try this below code.

open FILE, ">newseq.txt";
while($file =<DNAFILE>)
{
	my $dna = fasta($file);
	my $newseq = mutationdna($dna,$years);
	print FILE $newseq; #this does not work. how do I fix it?
	print $newseq; # this work
}

thank you, this solve the problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.