Hello

I need a short Perl subroutine that will recursively change the file paths in an HTML file to new file paths.

My HTML pages are designed to normally call graphics & server-side includes, etc from subfolders (as usual). But I have a perl program that needs to open, read the lines of one these html pages and output it as the output of the perl program.

The catch then, is that the references in the HTML are all wrong (images, links, server side includes, etc), since the Perl operates from the usual /cgi-bin folder, not from the usual HTML folder. The file structure is very standard, such as follows:

public_html
/cgi-bin
/images
/stylesheets
Further to that, the file references in the related SSI files in /stylesheets will be all wrong too.

I'm sure I've seen references in places to short scripts that will do this, and I'm looking to pick one of them up instead of writing it myself. In general it just needs to read an .html file line by line, try to match a text fragment & add in the "../" text. But it also needs to work recursively, identifying and opening the SSI's, and making the same subsitutions on them. I suppose this is the complicating factor that is making me look for a script - the reading and subsituting itself is straightforward.

Does anyone know of an existing script that will do this?

Alternatively, is there a different way to make this work? The real problem is that the server is working with /cgi-bin as the default directory, instead of the public_html folder above it, as it would with any regular websurfing.

Thank you so much.


In reply to Scripts to recursively reading in HTML files by mwhiting

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.