If you want to avoid regexes, you could use the URI module's path method in combination with the File::Spec::Unix module's splitpath function to get the filename. For example:

#!/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)' ), ( defin +ed( $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->fragm +ent ) ? $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)' ), ( def +ined($volume) ? $volume : '(undef)' ), ( defined($directories) ? $dir +ectories : '(undef)' ), ( defined($file) ? $file : '(undef)' ); PATH FRAGMENTS PATH: %s VOLUME: %s DIRECTORIES: %s FILE: %s PATH_PARTS

Another way to look at it, at least. Hope that helps.


In reply to Re: Regex simple quicky question :) by atcroft
in thread Regex simple quicky question :) by tanger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.