in reply to Re^3: Overwriting temp file
in thread Overwriting temp file

Thanks Again. Works like I want it too! Seek was good idea. You're pretty brainy. Here's what I ended up using.

#!/usr/bin/perl5.8.8 use strict; use warnings; #use autodie; dies if open/close...fail 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; open (my $TEMPfa,">",'temp'); while(<$INFILE>) { if ($_ =~/^##UniRef90_([\w\d]+) Protein Family/) { close ($TEMPfa); open ($TEMPfa,">",'temp'); seek $TEMPfa, 0 ,0; } if ($_ =~/^>UniRef90_[\w\d]+\.UniRef100_[\w\d]+/ || $_ =~/^[\w +\d]+/) { chomp $_; print $TEMPfa "$_\n"; } if ($_ =~/^>File/) { close ($TEMPfa); } } #end of while loop close ($INFILE); #closes the $INFILE handle } #end of subroutine tempProteinFamFileCreator

Replies are listed 'Best First'.
Re^5: Overwriting temp file
by Anonymous Monk on Sep 21, 2011 at 22:40 UTC

    Seek was good idea.

    My demo program needed seek because I did not want to touch the filesystem, so I used in-memory filehandles, and passed the filehandle around

    You don't need to use seek, it does nothing for you