[comp.lang.perl] dirname

me@anywhere.EBay.Sun.COM (Wayne Thompson - IR Workstation Support SE) (03/22/91)

This is an implementaion of dirname(1v) that I use that will do
the trick.

sub DirName {   # DirName ($dir)
    local ($_, $return) = @_;
    s#$#/#;
    (($return) = m#^(/)[^/]*/$#) ||
        (($return) = m#(.*[^/])/+[^/]+/+$#) ||
        ($return = '.');
    $return;
}
1;

And this is an example of how I do basename(1):

($MYNAME) = $0 =~ /([^\/]+)$/;

Wayne