Try
the File::Basename module like:
use
File::Basename;
$base
= basename($path);
$dir =
dirname($path);
($base,$dir,$ext) = fileparse($path);
Donald C. Stephens
Software Engineer
Analytics Prototyping and Scientific
Programming
Moody's KMV
Tel: 212.553.1346
Fax:
574.472.5990
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 21, 2005 2:59 PM
To: [email protected]
Subject: Filename pull
Hey, wizards.
I've got this problem: pulling the bare filename off of a fully pathed string, using split. The tricky part is getting the last element in the array when I don't know how many members are in it. Example:
$s1 = "c:\\temp\\foo.pl";
$barename = (split( /\\/, $s1)[2]; # $barename gets "foo.pl"
Now obviously this works as far as it goes, but what I should put inside those square brackets to make sure I always grab the filename, even in varied cases like these
$s2 = "c:\\windows\\fee\\fie\\fo\\fum\\foo.pl";
$s3 = "c:\\base_foo.pl";
is the question. If it was a regular array, I know I could get it using $#, like this:
@x = ("C:", "windows", "fee", "fum", "foo.pl");
$barename = $x[$#x];
Do I have to go to an intermediate step, assigning the output of split() to an array like @x? Or does someone have handy a regexp to do the dirty work?
Thanks!
Deane
-----------
The information contained in this e-mail message, and any attachment, is confidential and for use solely by the intended recipient. If you have received this message in error, please delete this message immediately. Although Moody's KMV makes every effort to protect its computing environment from malicious code, Moody's KMV is not responsible for any virus or other type of suspect code that may be transferred via this e-mail message.
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
