Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
if I want to modify a record in a file and I don't know whether the record I'm looking for already exists can I do that in one pass without having to write out the whole file. e.g. This is the pseudo code
If I do this and the value I'm searching for doesn't exist then I've re-written the entire contents of the original file needlessly. Hence is there anyway to redo the same loop so the first time round I see if the value exists and if it doesn't I don't bother creating an output file ? So a redo for the whole loop rather than the current iteration of the loop ?open file While (<file>) { if value exists then modify and print record to output file else print record to output file } rename output file back to original filename
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: redo entire loop
by roboticus (Chancellor) on Aug 13, 2010 at 14:54 UTC | |
Re: redo entire loop
by JavaFan (Canon) on Aug 13, 2010 at 15:05 UTC | |
Re: redo entire loop
by dasgar (Priest) on Aug 13, 2010 at 15:14 UTC | |
by ikegami (Patriarch) on Aug 13, 2010 at 16:01 UTC | |
Re: redo entire loop
by jonadab (Parson) on Aug 13, 2010 at 18:06 UTC | |
Re: redo entire loop
by Anonymous Monk on Aug 13, 2010 at 15:02 UTC | |
Re: redo entire loop
by zek152 (Pilgrim) on Aug 13, 2010 at 15:42 UTC |
Back to
Seekers of Perl Wisdom