Let's say I have the file.

# A B C # D E F #

I'm having difficulties with the logic. I enter and $INFILE (like the one above). Every time '#' is reached it indicates the end of the temp file. This temp file will be sent to two other subroutines for processing and it's output appended to a file.

I can't seem to get the temp file to overwrite.

First temp file should have this in it. # A B C
Second temp file should have this in it. # D E F

Here's what I've written so far. I'm mainly having problems with the scope of the filehandle. I've spent an embarrassing amount of time on this and would like to understand how to do it and move on.

#!/usr/bin/perl5.8.8 use strict; use warnings; print "Enter file to process\t"; my $count = <>; #captures input from STNDIN and finds the file associa +ted with that number chomp $count; tempProteinFamFileCreator(); #creates a temp file with protein family sub tempProteinFamFileCreator { my $infile = $count."_ProFam"; #iterates through all the protein famil +y files with the count variable open (my $INFILE,"<", $infile); my $flag = 0; while(<$INFILE>) { my $TEMPfa; if ($_ =~/^#/ && $flag == 0) { open ($TEMPfa,">", 'temp'); $flag++; } if ($_ =~/^[\w\d]+/) { chomp $_; print $TEMPfa "$_\n"; } if (($_ =~/^#/ && $flag == 1) || $_ =~/^>File/) { close ($TEMPfa); MuscleHMMERsearch(); TableParser(); } } close ($INFILE); #closes the $INFILE handle } #end of subroutine tempProteinFamFileCreator

Forever Thanks.

I've also tried...

#!/usr/bin/perl5.8.8 use strict; use warnings; print "Enter file to process\t"; my $count = <>; #captures input from STNDIN and finds the file associa +ted with that number chomp $count; tempProteinFamFileCreator(); sub tempProteinFamFileCreator { my $infile = $count."_ProFam"; #iterates through all the protein famil +y files with the count variable open (my $INFILE,"<", $infile); my $flag = 0; open (my $TEMPfa,">",'temp'); while(<$INFILE>) { if ($_ =~/^#/ && $flag == 0) { $flag++; } else { if ($_ =~/^[\w\d]+/) { chomp $_; print $TEMPfa "$_\n"; } if (($_ =~/^#/ && $flag == 1) || $_ =~/^>File/) { close ($TEMPfa); MuscleHMMERsearch(); TableParser(); open (my $TEMPfa,">",'temp'); } } } close ($INFILE); #closes the $INFILE handle } #end of subroutine tempProteinFamFileCreator

In reply to Overwriting temp file 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.