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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search file

Status
Not open for further replies.

Courtney1306

Programmer
May 30, 2007
14
US
I have a program in which the user is asked for two numbers. The program then searches a specific csv file and returns the count of the two numbers. The counts then need to be placed in the next two columns of the same file which was searched. The file I am reading in has three colums, about 5000 lines long. The first count would go in the fourth column, and the second count in the fifth. I am not having any luck adding the two counts. Is there something specific I need to do since I'm not writing to a new file?
 
There has been a "rash" of csv related questions lately.. do a search for the specific modules and code examples that everyone is posting.

This is the last question I remember being posted.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Those questions were from me as well, and they don't apply to this question.
 
Is there something specific I need to do since I'm not writing to a new file?

Use Tie::File if you are reading and writing to the same file.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Is there a way to do it without using a module? I need to avoid using a module as much as possible.

Courtney
 
Tie::File is a core module and is made for this purpose. Avoiding it's use is counter productive. Is this school/course work of some kind?

Other alternatives are using perls inplace editor or reading the whole file into an array, modifying the array, then overwriting the file with the array. The last suggestion is the least efficient and not good perl programming practice IMHO.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top