Perl for Website Administration
The Perl script below can be used to change a single line or word/phrase within a line on every page on the local copy of your website. Just copy and paste the code into a text file, modify the text to be found variable ($found)and the text to replace variable ($replaced) as required, change the file path variable ($webdir) as required then save the text file with the name replace and the extension.pl.
Stating the obvious here but you should make a backup of the website directory before you run this script.
my $found = qq|JavaScript|; #the text you're looking for
my $replaced = qq|javaScript|; #The replacement text
my $webdir = "Arkadyevna"; #Path to the local website
opendir my $dir, $webdir;
my @alldirs = readdir $dir;
closedir $dir;
foreach(@alldirs){
if($_ =~ /.html$/ && $_ !~ /^\./){ #change .html$ if required
print $_ . "\n";
my $filename = $webdir."/".$_;
my $data = read_file($filename);
$data =~ s/$found/$replaced/g;
write_file($filename, $data);
}
}
sub read_file {
my ($ofile) = @_;
open my $in, '<:encoding(UTF-8)', $ofile or die "Can't open '$ofile' $!";
local $/ = undef;
my $all = <$in>;
close $in;
return $all;
}
sub write_file {
my ($wfile, $content) = @_;
open my $out, '>:encoding(UTF-8)', $wfile or die "Can't open '$wfile' $!";
print $out $content;
close $out;
return;
}