I've got a bunch of programs that handle a website I'm working on, one of which is a main "server" program. It basically gets a single parameter: page location (for example: http://.../serve.pl?page=/perl/index.html). This works very nicely. This script "builds" the page (that is, /perl/index.html wouldn't have title html, the navigation stuff, etc; it's just the guts of that particular page).
The problem here is that in order for my page to actually display properly - title image, nav bar, etc - each page that is to be viewed gets run through this script. The problem arises that now every internal link has to change from "
<a href="/index.html">" to "
<a href="/serve.pl?page=/index.html">".
I've got a decent version working, but I'm wondering if Perl (or heck, even UNIX/Linux for that matter) provides some way of reducing paths. By this, I mean if I get a link that points to "../programs/blah.cgi" in, say, "/computing/perl/index.html", it will be smart enough to figure out the absolute path -- in this case, "/computing/programs/blah.cgi" -- rather than nested relative paths -- "/computing/programs/../perl/blah.cgi".
It's basically a matter of beautifying HTML through Perl. If the link were a directory, I could simply run a system call like:
$dir = `cd $some_link; pwd`;
chomp($dir);
(Knowing what to remove from the front of the new
$dir variable, such as /usr/local/apache/htdocs/.)
Any thoughts?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.