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


In reply to Finding & creating links in HTML files by heezy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.