duc has asked for the wisdom of the Perl Monks concerning the following question:
It works but I feel I could use a regex for it instead of a split, or maybe something else than using a match. So, the question is: is there a way to match only the last occurence of a character (like "/") in a string or any better way to get the directory of the file path? All ideas are welcomed !my $path = "D:/a directory/another directory/.../a file"; my @tmp = split(/\//, $path); my $last = @tmp - 1; $path =~ /\/$tmp[$last]/; my $dir = $PREMATCH; my $fileName = $tmp[$last];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: match only last character of a kind
by samtregar (Abbot) on Aug 17, 2006 at 18:57 UTC | |
by jwkrahn (Abbot) on Aug 17, 2006 at 19:37 UTC | |
by rodion (Chaplain) on Aug 17, 2006 at 20:00 UTC | |
by duc (Beadle) on Aug 17, 2006 at 20:15 UTC | |
|
Re: match only last character of a kind
by GrandFather (Saint) on Aug 17, 2006 at 19:42 UTC | |
|
Re: match only last character of a kind
by sgifford (Prior) on Aug 17, 2006 at 19:48 UTC | |
by duc (Beadle) on Aug 17, 2006 at 19:55 UTC | |
by duc (Beadle) on Aug 17, 2006 at 20:20 UTC |