--- Bruno Veldeman <[EMAIL PROTECTED]> wrote:
> I have a string with this format "/blabla/dir/nextdir/name.txt"
> I want only 'name.txt' in one string and the rest in another string.

my $string = '/blabla/dir/nextdir/name.txt';
my ( $path, $file ) = ( $string    =~ m!^(.*/)(.*)$! );

Breaking down the regex:

$string =~ m!^        # start at beginning of string
               (      # capture to $1
                 .*   #   zero or more of anything (except \n)
                 /    #   plus a slash
               )      # end capture
               (      # capture to $2
                 .*   #   zero or more of anything
               )      # end capture
             $!x;     # until end of string

Note that the \x modifier allows unescaped white space in the regex to be ignored.  
This is very
useful for commenting regexes.

In this case, however, I would recommend using File::Basename.

use File::Basename;
my $string = '/blabla/dir/nextdir/name.txt';
my $file = basename( $string );
my $path = dirname( $string );

Note that the final forward slash is not included in $path.  As a result, this does 
not *quite*
match your requirements.  Easy enough to add, though.

Cheers,
Curtis Poe


=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Reply via email to