[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Changing relative links to absolute



I'm having a dumb substitution problem--perhaps someone can catch my 
error, or show me a better way?

I created a first script to connect to a remote Web page, based on 
input from several sources, but unfortunately the page that I'm 
connecting to has relative links for displaying graphics, relative 
links to other pages, etc. These display as broken links in the page 
that my script returns to the user. I'm trying to do a few 
substitutions in my script, to change the relative links to absolute 
in the page that is returned to the user, but I'm afraid perhaps the 
syntax of the regular expression may be escaping me (unless I'm just 
plain doing this wrong). Here is the relevant section:

...

if ($resp->is_success) {
# change relative links to absolute
    $resp =~ s:src\=\"/:src\=\"http\://www.server.nyu.edu/:gi;
    $resp =~ s:href\=\"/:href\=\"http\://www.server.nyu.edu/:gi;
    print $resp->headers_as_string()."\n\n";
    print $resp->content;
} else {
    print $resp->error_as_HTML;
}

...

I used : instead of slashes for my regex delimiters, to make them 
stand out better and to cut down on the \/\/\/ stuff--of course, then 
I had to escape the : in "http:". Thing is, the substitution wasn't 
working when I used traditional slashes either. I don't generate an 
error when I run the script--it just doesn't change the links on the 
page from relative to absolute, the way I want it to!

Thanks for any "nudge" anyone can give me in the right direction,

--Eric


=====================
Eric L. Stedfeld
Info Tech Specialist
NYU Libraries
212 995-3545
eric.stedfeld@nyu.edu