URI
The URI module is a successor to URI::URL and was written by Gisle Aas. While not clearly stated in the LWP documentation, you should use the URI module whenever possible, since URI.pm has essentially deprecated URI::URL.
The URI module implements the URI class. Objects created from the URI class represent Uniform Resource Identifiers (URIs). With the URI module, you can identify the key parts of a URI: scheme, scheme-specific parts, and fragment identifiers, which may be referred to respectfully as authority, path, and query components. For example, as shown in the URI module documentation:
<scheme>:<scheme-specific-part>#<fragment> <scheme>://<authority><path>?<query>#<fragment> <path>?<query>#<fragment>
You can break down http://www.oreilly.com/somefile.html as:
scheme: http authority: www.oreilly.com path: /somefile.html
In the case of relative URIs, you can use the URI module to deal with only the query component of a URI. With the URI module, you can parse the above URI as follows:
#!/usr/local/bin/perl -w use URI; my $url = 'http://www.oreilly.com/somefile.html'; my $u1 = URI->new($url); print "scheme: ", $u1->scheme, "\n"; print "authority: ", $u1->authority, "\n"; print "path: ", $u1->path, "\n";
Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.