heezy has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
Applogies first off, this is my second question today (it's not a good day here at work)
I have a perl script that takes a list of file names and then cleans up the HTML that a certain Word Processor has produced as the HTML output.
I want to modify this so that if there is text in the document that should be a hyperlink but is not such as...
http://www.google.com
I want to identify that and change it to... <a href="http://www.google.com">http://www.google.com</a> so that it produces a nice link like http://www.google.com
My current code to tidy up the HTML looks something like..
#!/usr/bin/perl foreach $fname (@ARGV){ print "Processing: $fname\n"; open (FILE, $fname) || die("Cannot open file $fname! ($!)\n"); $file = join( "", <FILE>); close(FILE); rename ($fname, $fname.".bak"); $file =~ s/<META NAME=.*?>\n//gis; $file =~ s/<P STYLE.*?>/<P>/gis; $file =~ s/&ndash\;/-/gis; $file =~ s/&rdquo\;/\"/gis; $file =~ s/&ldquo\;/\"/gis; $file =~ s/<FONT.*?>//gis; $file =~ s/<\/FONT>//gis; $file =~ s/<SPAN.*?>//gis; $file =~ s/<\/SPAN>//gis; open (FILE, ">$fname"); print FILE $file; }
Anybody written anything likes this before or know a quick Perl-ish way of doing it?
Thanks in advance
M
Edit by tye, remove PRE tag around wide line
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding & creating links in HTML files
by fruiture (Curate) on Oct 17, 2002 at 23:11 UTC | |
|
Re: Finding & creating links in HTML files
by heezy (Monk) on Oct 17, 2002 at 20:20 UTC |