in reply to Handling relative urls with LWP or something else

If you have a look here you can check out the code of a link checker I wrote. Naturally it needs to crawl an entire site and correctly handle relative links. As you will see it takes lesss than half a dozen lines to do this.

Update

Actually looking at that code there is a subtle bug in it. Here is a complete sub that I will use to modify that code (one day :-)
print rel2abs( 'http://foo.com/aa/bb/cc', './../.././bar.htm' ); sub rel2abs { my ($root, $link) = @_; $link =~ s|^\s*/||; # trim link $root .= '/' unless $root =~ m|/$|; # ensure trailing / # move back up tree in response to ../ and ignore ./ while ( $link =~ s|^(\.?\./)|| ) { next if $1 eq './'; # effectively just delete ./ # trim dirs from root only until we can't go any further! $root =~ s|[^/]+/$|| unless $root =~ m|http://[^/]+/$|i; } return $root.$link; }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print