Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks , I have a question here . I have this input file which contain the following :
echo "insert into table1 values ('$1',sysdate,null,null,null,'OP',nul +l,'$5','IR',$2,$4,$3);" >> $OPONE } COW () { echo "insert into COLL values ('$1',sysdate,null,null,null,'OP',null,' +$5','$2','$3','$4','$6','0');" >> $OPCOW L_FILE } MONKS () { echo "insert into monks values ('$1',sysdate,null,null,null,'OP',null, +'$8','$5',2329,$2,$4,$3);" >> $OPTHREE } ARAMPSBADJ () { echo "insert into aramp values ('$1',sysdate,null,null,null,'OP',null, +'B');" >> $OP }
what I am trying to do is open that file and for the function monks change the value 2329 in the insert statment to somthing else let's say 9999 so my input file should look the same except for this line
MONKS () { echo "insert into monks values ('$1',sysdate,null,null,null,'OP',null, +'$8','$5',9999,$2,$4,$3);" >> $OPTHREE }
Can some one show me the best way to do it : , I am trying somthing like
while(<INPUT>) { if ( $flag == 1 ) { s/MONKSPART/MONKSPART$newchanges/ if /MONKS ()/; $flag = 0 if /^fi/; } $flag = 1 if /^}/; }

Replies are listed 'Best First'.
Re: Changing input file
by CountZero (Bishop) on Feb 06, 2004 at 20:53 UTC
    I suggest that when reading the records in this file you local change the record-separator $/ to }, so you read each record in one step (avoiding messy issues with newlines etc.)

    Then it is just a matter of s/MONKS.+?(2329)/9999/

    I'm not sure what you mean with $flag etc. but it has probably some meaning in your program.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law