igotlongestname has asked for the wisdom of the Perl Monks concerning the following question:
I think some error is occuring, because the text in the scalar replace variable has the word "END" in it as well, but the code doesn't get stuck in an infinite loop, it just adds some screwy lines along with the correct ones. I am sure I am doing this backwards and someone here has a better idea and I'm all for hearing it. Any further questions are welcomed as well. Thanks! Update: I figured it'd be easier if I posted what was in each file: The end of the file to be altered (note the "END" is what I want to change)$COMPFILE = IO::File->new; #!!!!!!!!!!!!!!!!!!!!!!!!! SCALAR SLURP !!!!!!!!!!!!!!!!!!!!!!!! $comptmplt_file="comp_template.txt"; { local $/; open SLURP, $comptmplt_file or die "sudden death"; $comptmplt=<SLURP>; close SLURP or die "cannot close $comptmplt: $!"; } #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! $COMPFILE->open("+< comp_no_rods.txt" or die "Can't open"); print "$comptmplt"; until ($COMPFILE -> eof){ $compline = $COMPFILE->getline(); if ($compline=~ /END/){; $compline=~ s/END/$comptmplt/; print $COMPFILE "$compline"; } }
The text to be inserted in place of the "END"! ========================================================== TITLE T2 C1 2V-03-12100 9193 - 9406 EFPH. UTBR STEG NR 018 OPTION Burnup,Neu3,NoSearch,TTable,FlwTot,NoPowEnd PRINT KEYPAR INIT /sompath/dist-9193.dat=HIST SAVE /somepath/dist-9406.dat=POWER,HIST,TM,TIPNEU,PRMNEU,CRWDR, SAVE * PINPOW,PINBUR,PINLHR,PINFIM,PINDRY POWER 88.900 FLOW 7737.0 PRESS 70.000 CONROD ALL=100 BURNUP 213.0000, 1, EFPH, Straight-Euler END
I will do this once, do some calculations, check to see if I have satisfied a criteria. If I haven't, I'll add more data to the file by changing the "END" in the exact same way above, with the file growing by another addition of data, then re-run a calculation. (Hopefully that makes sense). If you want to see the output I currently get, feel free to ask. Thanks again.! ========================================================== TITLE T2 C1 2V-03-12100 BEGIN - FINISH EFPH. UTBR STEG NR 018 OPTION Burnup,Neu3,NoSearch,TTable,FlwTot,NoPowEnd PRINT KEYPAR INIT /somepath/dist-BEGIN.dat=HIST SAVE /somepath/dist-FINISH.dat=POWER,HIST,TM,TIPNEU,PRMNEU,CRWDR, SAVE * PINPOW,PINBUR,PINLHR,PINFIM,PINDRY POWER 100.0 FLOW 6500 PRESS 70.000 CONROD ALL=100 BURNUP 500.0000, 1, EFPH, Straight-Euler END
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: text file search and replace
by jwkrahn (Abbot) on Feb 19, 2008 at 20:05 UTC | |
|
Re: text file search and replace
by Narveson (Chaplain) on Feb 19, 2008 at 18:28 UTC | |
by igotlongestname (Acolyte) on Feb 19, 2008 at 18:45 UTC |