Hi,
I'm currently writing a perl script and it's my first time doing this. So I'm not sure why I can't seem to write to the same file that I am reading. I read somewhere that I cannot read and write at the same time. Is this true? If not, can you help me in solving this writing problem I am having? Below is my code:
my $midtierGS=`ls mtb_*_*_*_hnw_g s.xml`;
my $disclaimer="DY NAMIC_DISCLAIME R_IMPLEMENTED";
my $provider="MKD_ CURRENT_DATA_PR OVIDER";
open(FILE,"+<$m idtierGS") or die "Couldn't open file!";
#read line from file
while ($record = <FILE>) {
#if line contains value
if ($record =~ m/$disclaimer/) {
#go to next line
$nextLine = <FILE>;
#substitute old value for new value
$nextLine =~ s/false/true/;
#save changes to file
print FILE "$nextLine" ;
}
elsif ($record =~ m/$provider/) {
$nextLine = <FILE>;
$nextLine =~ s/RSF/Comstock/;
print FILE "$nextLine" ;
}
}
close FILE;
I'm currently writing a perl script and it's my first time doing this. So I'm not sure why I can't seem to write to the same file that I am reading. I read somewhere that I cannot read and write at the same time. Is this true? If not, can you help me in solving this writing problem I am having? Below is my code:
my $midtierGS=`ls mtb_*_*_*_hnw_g s.xml`;
my $disclaimer="DY NAMIC_DISCLAIME R_IMPLEMENTED";
my $provider="MKD_ CURRENT_DATA_PR OVIDER";
open(FILE,"+<$m idtierGS") or die "Couldn't open file!";
#read line from file
while ($record = <FILE>) {
#if line contains value
if ($record =~ m/$disclaimer/) {
#go to next line
$nextLine = <FILE>;
#substitute old value for new value
$nextLine =~ s/false/true/;
#save changes to file
print FILE "$nextLine" ;
}
elsif ($record =~ m/$provider/) {
$nextLine = <FILE>;
$nextLine =~ s/RSF/Comstock/;
print FILE "$nextLine" ;
}
}
close FILE;
Comment