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
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to