Jeri has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Overwriting temp file
by Anonymous Monk on Sep 21, 2011 at 18:41 UTC | |
by Jeri (Scribe) on Sep 21, 2011 at 18:45 UTC | |
|
Re: Overwriting temp file
by Anonymous Monk on Sep 21, 2011 at 18:52 UTC | |
by Jeri (Scribe) on Sep 21, 2011 at 18:54 UTC | |
by Anonymous Monk on Sep 21, 2011 at 19:37 UTC | |
by Jeri (Scribe) on Sep 21, 2011 at 20:30 UTC | |
by Anonymous Monk on Sep 21, 2011 at 22:40 UTC | |
by Jeri (Scribe) on Sep 21, 2011 at 20:04 UTC | |
by Khen1950fx (Canon) on Sep 21, 2011 at 22:57 UTC | |
by Jeri (Scribe) on Sep 22, 2011 at 14:07 UTC | |
by Anonymous Monk on Sep 22, 2011 at 14:21 UTC |