My english is not very good but if I understand, want you this?

$s1 = "c:\\windows\\fee\\fie\\fo\\fum\\foo.pl";
@x = (split( /\\/, $s1);
$barename=$x[$#x];

$s1 = "c:\\foo.pl";
@x = (split( /\\/, $s1);
$barename=$x[$#x];

Petr Vileta, Czech republic
(My server reject all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, April 21, 2005 8:59 PM
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


----------------------------------------------------------------------------
----


> _______________________________________________
> ActivePerl mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to