Q:
Hello Peter
I am a Perl beginner and I am trying to create a script to rename all htm
files in a directory to html, i want to change any references of "http" to
"https" within the html files and i want to change all html tags to upper
case.
I am then trying to record in a logfile:
1. each file that has been modified and
2. the tags within it that have been modified
I am also trying to find a way to run the search on any subdirectories
within the main directory.
I tried using use strict but it gave me errors, do you know how I can use
strict effectively?
Your help is greatly appreciated.
I have included my script below to show you how much I have achieved but I
can only get to the point of determining the directory and creating the
logfile.
I am running this script on win2000 but can modify to test on Linux.
#!/usr/bin/perl
# use strict;
print "Enter a directory\n";
$dirname = <>;
chomp $dirname;
if (-d $dirname and -e $dirname)
{
print "$dirname is a directory\n";
opendir(DIR, $dirname);
@filenames = readdir(DIR);
print "Directory is $dirname\n";
foreach $filename(@filenames){
chomp($filename);
if (-d $dirname."/".$filename) {
print "$dirname/$filename is a directory\n";
}
else{
print "$dirname/$filename is a file\n";
}
}
}
else{
print "$filename does not exist or its not a directory\n";
}
@listarray = <$OLD>;
#puts whole file into an array
$string = join('', @listarray);
# makes one string out of array
$_ = $string;
print "$string";
s/http/https/gi;
#replace any instance of http with https
open ($LOG, "> logfile.txt");
select($LOG);
print("$string"); # write to selected output ($LOG)
close ($LOG);
close ($OLD);
A:
use strict will require you to declare each variable.
Other than that I see no specifiq question in your mail that I could
answer.
Visit
http://peter.verhas.com/progs/perl/webunify/index.html
to see some similar program.
Regards,
Peter
[ back to toc ]