This is the umpty-umpth writer to point me at File::Basename. Thanks to all!
Deane
| "Arms, Mike" <[EMAIL PROTECTED]>
04/21/2005 15:32
|
To: [email protected] cc: [EMAIL PROTECTED] Subject: RE: Filename pull |
> 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.
If you insist on using split, then use the -1 index:
$basename = (split( m#[\\/]#, $s1)[-1];
Alternatively, you could use a regex:
$basename = $s1 =~ m#^.*[\\/](.*)# ? $1 : $s1;
The reason for the conditional is that $s1 might not have
any directory separators in it (that is, just the filename).
But a better solution is to use the File::Basename module.
--
Mike Arms
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
