Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: Overwriting temp file

by Jeri (Scribe)
on Sep 21, 2011 at 20:30 UTC ( [id://927221]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://927221]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-19 05:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found