Почему не происходит замены в файле?
Скрипт вот:
Код:
#!/use/bin/perl -w
use strict;
open(OF, "+< /var/www/d-link/conf")
While(my $file = <OF>)
{
$file =~ s/sa/ppp/g;
}
close(OF);
use strict;
open(OF, "+< /var/www/d-link/conf")
While(my $file = <OF>)
{
$file =~ s/sa/ppp/g;
}
close(OF);
Код:
open(IF, "< /var/www/d-link/conf") or die $!;
open(OF, "> /var/www/d-link/conf.tmp" ) or die $!;
while(<IF>)
{
s/sa/*/g;
print NEW $_;
}
close(OF);
close(IF);
#copy new to old:
rename $/var/www/d-link/conf, /var/www/d-link/conf.bkp;
rename $/var/www/d-link/conf.tmp, /var/www/d-link/conf;
open(OF, "> /var/www/d-link/conf.tmp" ) or die $!;
while(<IF>)
{
s/sa/*/g;
print NEW $_;
}
close(OF);
close(IF);
#copy new to old:
rename $/var/www/d-link/conf, /var/www/d-link/conf.bkp;
rename $/var/www/d-link/conf.tmp, /var/www/d-link/conf;