in reply to match only last character of a kind

As others have said, File::Basename is definitely the right way to go for this particular problem.

In general, though, you can do this sort of thing with a regular expression by using a character class that doesn't include the seperator. For example:

if ($path =~ m|^(.*)/[^/]*$|) { $dir = $1; }
will grab everything up to the last slash.

Replies are listed 'Best First'.
Re^2: match only last character of a kind
by duc (Beadle) on Aug 17, 2006 at 19:55 UTC
    Thanks ! I will try File::Basename.
      Well, thanks for all the information. I have used File::Basename and it works magnificiently for what I want to do. But I will also keep the other solution in mind, I need to match last occurences also. :) And sorry about the title, I kind of ask two questions at once.