Hello! I want my temp file to be overwritten every time I use it, but instead it keeps appending my data to it. How do I go about emptying it out?

forever thanks
#!/usr/bin/perl5.8.8 use strict; use warnings; tempProteinFamFileCreator(); sub tempProteinFamFileCreator { print "Enter file to process\t"; my $count = <>; #captures input from STNDIN and finds the file associa +ted with that number chomp $count; my $TEMPfa; #file handle to temp file which stores a protein family my $infile = $count."_ProFam"; #iterates through all the protein famil +y files with the count variable open (my $INFILE,"<", $infile); open ($TEMPfa,">","temp"); #opens temp file while(<$INFILE>) { #putting a single protein family into a temp file and processing i +t with two more subroutines if ($_ =~/^##UniRef90_([\w\d]+) Protein Family/) { close ($TEMPfa); MuscleHMMERsearch(); TableParser(); open ($TEMPfa,">","temp"); #opens temp file } if ($_ =~/^>UniRef90_[\w\d]+\.UniRef100_[\w\d]+/) { chomp $_; print $TEMPfa "$_\n"; } if ($_ =~/^[\w\d]+/) { print $TEMPfa $_; } if ($_ =~/^>File/) #indicates end of file { close ($TEMPfa); MuscleHMMERsearch(); TableParser(); } } close ($INFILE); #closes the infile handle } sub MuscleHMMERsearch { #checking if the temp file has data or is empty if ($_ =~/^>(UniRef90_[\w\d]+)\.UniRef100_[\w\d]+/) { # MUSCLE creating a multiple alignment file my $Fprot = "temp"; #temp file is sent to MUSCLE my $maFprot = $1."_ProFam.afa"; my $cmd = "/home/vcg/Documents/Trial/muscle -in $Fprot -out $maFpr +ot"; print $cmd. "\n"; system ($cmd); if ($?) {die "command $cmd failed\n"}; #system (rm /chongle/jeri/bin/temp.fa); # HMMER creating a profile HMM from a multiple alignment file my $hmm_Fprot = $1."_ProFam.hmm"; $cmd = "/home/vcg/Documents/Trial/hmmbuild --informat afa $hmm_Fpr +ot $maFprot"; print $cmd. "\n"; system ($cmd); if ($?) {die "command $cmd failed\n"}; #system (rm /chongle/jeri/bin/$maFprot); # Searching the sequence database with hmmsearch my $results = $1."_PFhmmResults.out"; $cmd = "/home/vcg/Documents/Trial/hmmsearch --tblout HMMtable.tbl +--cpu 1 -E .001 $hmm_Fprot uniref100.fasta"; #HMMtable is not being b +uilt #Is only one family going through and only outputting one empty +file? print $cmd. "\n"; system ($cmd); if ($?) {die "command $cmd failed\n"}; #system (rm /chongle/jeri/bin/$hmm_Fprot); } else {print "File is empty\n";} } sub TableParser { open (my $TABLE,"<","table.tbl"); open (my $OUTFILE,">","FamDATA"); print $OUTFILE "target name\tE-value\tscore\n"; while(<$TABLE>) #space delimited file { if ($_=~/^#/){next;} my @data = split(" ", $_); if ($_=~/^UniRef100/) { my $TargetName = $data[0]; my $E_value = $data[4]; my $BitScore = $data[5]; print $OUTFILE "$TargetName\t$E_value\t$BitScore\n"; } } close ($TABLE); close ($OUTFILE); }

In reply to Appending and empty files by Jeri

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.