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.
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
In reply to Re: Handling relative urls with LWP or something else
by tachyon
in thread Handling relative urls with LWP or something else
by George_Sherston
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |