in reply to Clean way to build URI's?

If the source of $domain is trusted, interpolation is fine because the domain can't contain any character that need escaping. That's not the case for $class, $user and $function. If they're untrusted or if they can contain most of anything other than letters and digits, they need to be escaped.

Here's a solution using URI.

use URI qw( ); my $url = URI->new("http://$domain:2087"); $url->path_segments('xml-api', $class); $url->query_form( user => $user, $function => 1 ); print "$url\n";

Or if you don't trust $domain,

use URI qw( ); my $url = URI->new('', 'http'); $url->host("$domain:2087"); $url->path_segments('xml-api', $class); $url->query_form( user => $user, $function => 1 ); print "$url\n";

Replies are listed 'Best First'.
Re^2: Clean way to build URI's?
by rastoboy (Monk) on Feb 02, 2010 at 23:21 UTC
    Thanks to you all! I'll have a play with CGI::Enurl and URI both.

    I had checked our URI, but it didn't look like what I needed--but I see now I was mistaken :-)
    Thanks again!