programingnoob
Technical User
Hi,
I have come for help again, seeing that so many of you people are so nice and helpful
My program is suppose to find a word and add something behind it, which it does. After succeeding, I have try to put a limit on how many words my program will replace. My program did replace the words, but the words that it didn't replace is deleted!
What is wrong with my program? How can I correct it?
Here's my program --------------------------------------
#!/usr/bin/perl
$file=test.txt; #file to edit
$quan=1; #limit of $word that the program would edit
$word="plain"; #word that I am trying to find
$rword="(white)"; #word that I am trying to add behind $word
$num=0;
open IN, $file;
while ($ln=<IN>) {
if ($ln==$word and $quan>0) {
$ln=qq|$word $realset|;
$quan--;
} else {
$ln=$ln;
}
$setedit[$num]=$ln;
$num = $num +1;
}
close IN;
open OUT, ">$file";
print OUT @setedit;
close OUT;
#end
---------------------------------------------------------
Also, how do I delete or edit posts in Tek-tips?
Have a nice day !
KT
I have come for help again, seeing that so many of you people are so nice and helpful
My program is suppose to find a word and add something behind it, which it does. After succeeding, I have try to put a limit on how many words my program will replace. My program did replace the words, but the words that it didn't replace is deleted!
What is wrong with my program? How can I correct it?
Here's my program --------------------------------------
#!/usr/bin/perl
$file=test.txt; #file to edit
$quan=1; #limit of $word that the program would edit
$word="plain"; #word that I am trying to find
$rword="(white)"; #word that I am trying to add behind $word
$num=0;
open IN, $file;
while ($ln=<IN>) {
if ($ln==$word and $quan>0) {
$ln=qq|$word $realset|;
$quan--;
} else {
$ln=$ln;
}
$setedit[$num]=$ln;
$num = $num +1;
}
close IN;
open OUT, ">$file";
print OUT @setedit;
close OUT;
#end
---------------------------------------------------------
Also, how do I delete or edit posts in Tek-tips?
Have a nice day !
KT