#!/usr/bin/perl -w use strict; use File::Spec::Unix; use URI; # # url: http://www.made_up_name.com/somepath/script.php/image.jpg?p=1&q=2#name # # $u->scheme: http # $u->userinfo: (undef) # $u->host: www.made_up_name.com # $u->port: 80 # $u->path: /somepath/script.php/image.jpg # $u->query: p=1&q=2 # $u->fragment: name # my $url = join( '://', 'http', join( '/', 'www.made_up_name.com', 'somepath', 'script.php', join( '?', 'image.jpg', join( '#', join( '&', 'p=1', 'q=2' ), 'name' ) ) ) ); my $u = URI->new($url); # # $u->path: /somepath/script.php/image.jpg # # $volume: '' # $directories: /somepath/script.php/ # $file: image.jpg # ( my $volume, my $directories, my $file ) = File::Spec::Unix->splitpath( $u->path ); printf << "URI_PARTS", $url, ( defined( $u->scheme ) ? $u->scheme : '(undef)' ), ( defined( $u->userinfo ) ? $u->userinfo : '(undef)' ), ( defined( $u->host ) ? $u->host : '(undef)' ), ( defined( $u->port ) ? $u->port : '(undef)' ), ( defined( $u->path ) ? $u->path : '(undef)' ), ( defined( $u->query ) ? $u->query : '(undef)' ), ( defined( $u->fragment ) ? $u->fragment : '(undef)' ); URI PARTS URL: %s SCHEME: %s USERINFO: %s HOST: %s PORT: %s PATH: %s QUERY: %s FRAGMENT: %s URI_PARTS printf << "PATH_PARTS", ( defined($u->path) ? $u->path : '(undef)' ), ( defined($volume) ? $volume : '(undef)' ), ( defined($directories) ? $directories : '(undef)' ), ( defined($file) ? $file : '(undef)' ); PATH FRAGMENTS PATH: %s VOLUME: %s DIRECTORIES: %s FILE: %s PATH_PARTS