Hi,

> > 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.

Thanks for the solution.

> in this case, i would use split:
>
> $location = "/blabla/dir/nextdir/name.txt";
> @dirs = split("\/", $location);

But then, would it be posible to do it with a regex? Would it be less
efficient?

And another thing:
> print $dirs[$#dirs];

What is this? I thought that $dirs would give the number of elements in the
array.
So what is the "#" for? Is it like ($dirs-1) or something?



------------------------------------------------------------
----- Original Message -----
From: "fliptop" <[EMAIL PROTECTED]>
To: "Bruno Veldeman" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Saturday, June 09, 2001 11:10 PM
Subject: Re: Regex question


> Bruno Veldeman 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.
>
> in this case, i would use split:
>
> $location = "/blabla/dir/nextdir/name.txt";
> @dirs = split("\/", $location);
>
> foreach (@dirs) { print "$_\n"; }
>
> will yield:
>
>
> blabla
> dir
> nextdir
> name.txt
>
> and you can access what you want directly by using:
>
> print $dirs[4];
>
> or, if you don't know how many directories will be in there:
>
> print $dirs[$#dirs];
>
> > Or better, how do I learn to use regex?
>
> i'd recommend Jeffrey Friedl's book, 'Mastering Regular Expressions',
> which is available from O'Reilly & Associates.

Reply via email to