in reply to Re: Extract Name of Parent Directory
in thread Extract Name of Parent Directory

if you *really* feel like reinventing the wheel

Well, if you really must, at least make it short.

my $dir = "/htdocs/project1/docs/file.html"; my $parent = (split /\//, $dir)[-2];

Replies are listed 'Best First'.
Re: Re: Re: Extract Name of Parent Directory
by gellyfish (Monsignor) on Jul 17, 2003 at 10:29 UTC

    man, you guys have obviously never been paid by the line of code - let's use the power of timtowtdi to make this even longer:

    my $file = "/htdocs/project1/docs/file.html"; my $elif = reverse $file; my $slash = index($elif,'/'); my $index = length( $file ) - $slash; $index--; my $dir = substr($file,0, $index); print $dir;
    You know it makes sense ;-)

    /J\