Nishi wrote:

What is the equivalent of basename? Ie if I dont want to use basename
package to get the filename off a path, what reg expr can i use in perl?

Would this work --
my $fileName=$path =~ /.*\/(.+)$/;

Why don't you try it?!

It wouldn't work because $fileName would end up with either a true or a
false value depending on whether the regex matched. To get the captured
string put the regex in list context:

 my ($fileName) = $path =~ /.*\/(.+)$/;

But it would still fail if there was no slash in the $path string. You
may want to use the slightly simpler

 my ($name) = $path =~ m|([^/]+)$|;

which just grabs all the characters at the end of the string that aren't
slashes, and works whether or not there is a path as well as a file name
in the string.

Cheers,

Rob



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to