Search notes:

Perl module URI

The Perl module URI can be used to split an URL into its parts
#!/usr/bin/perl
use warnings;
use strict;

use URI;

my $uri = URI->new("http://xxx.yy.ch:8080/a/b/c.html?vier=4&fuenf=5");

print "Scheme: ",$uri->scheme,"\n";
print "Path:   ",$uri->path  ,"\n";
print "Host:   ",$uri->host  ,"\n";
print "Port:   ",$uri->port  ,"\n";
print "Query:  ",$uri->query ,"\n";
Github repository PerlModules, path: /URI/script.pl
This script prints
Scheme: http
Path:   /a/b/c.html
Host:   xxx.yy.ch
Port:   8080
Query:  vier=4&fuenf=5

Combining absolute and relative urls

new_abs can be used to create an absolute url from an existing absolute and relative url.
#!/usr/bin/perl
use warnings;
use strict;

use URI;

my $absolute_url = 'http://www.host.xyz/path/to/a/page.html';
my $relative_url = '../../of/another/resource.html';

print URI->new_abs($relative_url, $absolute_url), "\n";
Github repository PerlModules, path: /URI/combine-absolute-and-relative-url.pl
prints
http://www.host.xyz/path/of/another/resource.html

See also

Perl modules, URI::Encode URI::Find
URI: Uniform Resource Identifier

Index