in reply to converting absolute to relative links
However this code is untested and may well need some work. It currently would take input on STDIN and produce results on STDOUT.use URI; use HTML::Parser; my $parse = new HTML::Parser( default_h => [ sub {print shift}, 'text' + ], start_h => [ sub { my ($tag, $attr, $origtext) = @_; if (($tag eq 'img') and ($attr->{src} =~ m#^(?:http://)?myserver\. +#)) { $attr->{img} = URI->new($attr->{img})->abs('http://myserver.com' +); print "<$tag " . join (' ', map {$_.'="' . $attr->{$_} . '"'} ke +ys %$attr) . '>'; } else { print $origtext; } }, "tagname, attr, text"] ); $parse->parse(join('',<>));
|
|---|