Hi all,
I'm trying to read in a bunch of files and insert the contents of the <h1>
tag into the <title> tag, writing the output to a temp file.
Am getting this error:
Use of uninitialized value at title.pl line 28, <IN> chunk 14.
Which is this line:
$_ =~ s#$pattern2#<title>$title</title>#g;
I'm not sure why I'm getting this error.
Thanks in advance,
Pam
Sample file
------------------------------------------------------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<!-- style for screen and print -->
<link rel="stylesheet" href="cat.css" type="text/css" media="screen" />
<link rel="stylesheet" href="print.css" type="text/css" media="print" />
</head>
<h1>Beginning Acting I</h1>
Code:
----------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
my($file, @files, $title);
@ARGV = glob('*.html');
@files = @ARGV;
foreach $file(@files) {
#open files
print("OPEN: $file\n");
open(IN, "$file") or die ("can't open in file: $!");
my $outfile = "$file.tmp";
open(OUT,">$outfile") or die ("can't open outfile: $!");
while(<IN>){
my $pattern1 = "\<h1>\(.*\)<\/h1>";
my $pattern2 = "<title><\/title>";
if ($_ =~ /$pattern1/){
$title = $1;
print("$_");
#print OUT ("$_");
}
elsif ($_ =~ /$pattern2/){
$_ =~ s#$pattern2#<title>$title</title>#g;
print("$_\n");
#print OUT ("$_");
}
else{
print("$_");
#print OUT ("$_");
}
} #end while file contents
close IN;
close OUT;
} #end foreach
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>