Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Handle Settings

Status
Not open for further replies.

BStopp

Programmer
Dec 29, 2003
29
US
According to everything I can find on the subject, if i were to open a file in mode +< I should be able to read the file, write to the file, and clobber existing (this i take to me overwrite current position of file).

Does this actually work? If so, is there a specific way you must reference the file, such as:

Can i do a "foreach $line (<fh>)" or
do i have to do a "while (<fh>)"

I realize I can read the file into an array and then replace the file with the altered contents of the array. However I'm in need of doing it with up to multiple gig file sizes.

B
 
do it the long way and charge by the byte
--just an idea
--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
In my experience, if you open a file with +< you can read it or write to it, but writes take place at the end of the file, not at the current read position. I believe "clobber" in this context (>+) means "erase existing file contents."

If your file is huge, slurping to an array is not the way to go. Why not describe what you're trying to do and perhaps we can help.


 
Multiple gb file sizes, sounds interesting...

Mike

To err is human,
but to really foul things up -
you require a man Mike.

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Basically what I am trying to do is remove bad information from a archived data file. The data files in the archive themselves are not multiple gb. But in order to get the data I need from them, i search this whole archive and pull back specific records inside each file and put them all into one file. After that I need to do a few things, one of them is removing any record from the file that contains characters not found on any standard US keyboard (Hence my other post yesterday). If i can just so a s/// on the entire record and replace that specific one in the file, that would be extremely helpful. THe other thing I need to do is find out if the length of the record is reported correctly inside of the record, if not, i need to correct it.

As you can see it would be much easier for me to just modify the file in place without having to read each line into memory or open two files and rifle through one and print to the other. If anyone has any suggestions, i'd like to hear them.

B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top