tags:

views:

293

answers:

5

I'm currently using URI::URL to generate this, however it is isn't as fast as I'd like it to be. Does anyone know another way to do this that may be faster?

A: 

Perhaps I got the wrong end of the stick but wouldn't,

$full_url = $base_url . $relative_url

work? IIRC Perl text processing is pretty quick.

@lennysan Ah sure yes of course. Sorry I can't help, my Perl is pretty rusty.

Brendan
+3  A: 

The following code should work.

$uri = URI->new_abs( $str, $base_uri )

You should also take a look at the URI page on search.cpan.org.

Peter Stuifzand
+1  A: 

Brendan, I should have clarified that I can't guarantee what the relative path is going to look like. It could be pretty tricky (e.g. has a slash at the front, doesn't have a slash, has "../", etc).

Peter, that's what I'm using now. Or is that faster then using the URI::URL->new($path)->abs?

lennysan
+3  A: 

Just happened across this article which point out shortcomings in Redhat/Centos/Fedora implementations of Perl which affect URI profoundly.

If you are running one of these Linux flavours, you might want to recompile Perl from original source (not RPM source).

I realized that anyone running perl code with the distribution perl interpretter on Redhat 5.2, Centos 5.2 or Fedora 9 is likely a victim. Yes, even if your code doesn’t use the fancy bless/overload idiom, many CPAN modules do! This google search shows 1500+ modules use the bless/overload idiom and they include some really popular ones like URI, JSON. ...

... At this point, I decided to recompile perl from source. The bug was gone. And the difference was appalling. Everything got seriously fast. CPUs were chilling at a loadavg below 0.10 and we were processing data 100x to 1000x faster!

Brendan
+1  A: 

Could depend a bit how you obtain those 2 strings. Probably the secure, fireproof way to do that is what is in URI::URL or similar libraries, where all alternatives, including malicious ones, would be considered. Maybe slower, but in some environments faster will be the speed of a bullet going to your own foot.

But if you expect there something plain and not tricky could see if it starts with /, chains of ../, or any other char. The 1st would put the server name + the url, the 2nd chop paths from the base uri till getting in one of the other 2 alternatives, or just add it to the base url.

gmuslera