PDA

View Full Version : Works for <title> but no other HTML tag


carl_mcdade
02-27-2005, 12:13 PM
this works fine:

#!/usr/bin/perl
use strict;

my $dir = './';
my $newdir = './updated_1';
my @dir = ();

opendir(DIR, $dir);
@dir = readdir(DIR);
closedir(DIR);

foreach my $file (@dir) {
if($file =~ /\.html$/ && -T $file) {
my $new_name;
open(FILE, "<$dir/$file");
while(<FILE>) {
if(/\<title\>(.*?)\<\/title\>/i) {
$new_name = $1 . '.html';
last;
}
}
close(FILE);
print "$file -> $new_name\n";
rename($dir . '/' . $file, $newdir . '/' . $new_name);
}
}
But changing it to

if(/\<h2\>(.*?)\<\/h2\>/i) {
gives no results.

What am i missing here?

carl_mcdade
02-27-2005, 01:00 PM
Here's the string I anm trying to match:

<H2>Programs to use for translation
<H6>[Translator's guide]</H6></H2>

carl_mcdade
02-27-2005, 01:40 PM
no matches for:

\<h2\>(.*?\n)\<h6\>\[(.*?)\]\<\/h6\>\<\/h2\>

or

\<h2\>(.*?)(\r|\n|\s)?(.*?)\<\/h6\>\<\/h2\>/i

I am running this script in cygwin.

carl_mcdade
02-28-2005, 10:57 AM
Okay, so I was getting a match but because I am using command line to run the script there was no message when the file name was not present.

What I need now is a good tutorial on Perl error checking so that I can modify the scripts that I am using.

rwedge
03-06-2005, 03:29 AM
You can use CGI::Carp to display error messages to the browser or write them to a file

#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);

- or -

#!/usr/bin/perl
BEGIN {
use CGI::Carp qw(carpout);
open(LOG, ">cgi-error.log")
or die "Unable to write to mycgi-log: $!\n";
carpout(*LOG);
close(LOG);
}
use strict;
use warnings;



/Bob