in reply to match only last character of a kind

Use File::BaseName. Example:

use File::Basename; my ($filename, $dir, $suffix) = fileparse($path); print "The directory is: $dir\n";

For more complex path-spliting, check out File::Spec.

-sam

Replies are listed 'Best First'.
Re^2: match only last character of a kind
by jwkrahn (Abbot) on Aug 17, 2006 at 19:37 UTC
    Or just:
    use File::Basename; my $dir = dirname $path; print "The directory is: $dir\n";
Re^2: match only last character of a kind
by rodion (Chaplain) on Aug 17, 2006 at 20:00 UTC
    Another reason for using File::Basename instead of a RE is that it will change the dir separator to the appropriate slash from backslash when you move from Windows to *nix.

    Update: I mention this in particular because the slashes are going one direction in the OP text and the other way in the code section of the OP. (It can be quite quite hard to keep straight.)

      So it is portable.. which is good, the script I am writing will always run on windows because it is modifying the registry but leave some space to change. :)