in reply to Data Extraction Question

Something like
$dir = $templ; $dir =~ s%/[^/]+$%/%;
Essentially it deletes everything to the right of the last '/' character found.
Caution: I haven't tested this.

Replies are listed 'Best First'.
Re^2: Data Extraction Question
by amphiplex (Monk) on Aug 03, 2004 at 12:59 UTC
    This is not completely correct, I think:

    for /proj/home/me/asdf.p your code would correctly give: /proj/home/me/

    but for asdf1.pl the result would be: asdf1.pl

    another approach:

    my $temp1 = "/proj/home/me/asdf.pl"; print my_dirname($temp1) ."\n"; $temp1 = "asdf1.pl"; print my_dirname($temp1) ."\n"; $temp1 = "/asdf1.pl"; print my_dirname($temp1) ."\n"; sub my_dirname { my ($dir) = $_[0] =~ m|^(.*/)|; return $dir; }

    ---- amphiplex