http://www.perlmonks.org?node_id=993661

Divakar has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

i have to split directory and file from below lines.

/vobs_ostore/osci/scripts/utils/ostore_release

from this i have to get like this.

$dir_name=/vobs_ostore/osci/scripts/utils/

$file_name=ostore_release.

i dont know how to split and get it.

any help please?

Thank you...

Replies are listed 'Best First'.
Re: How to seperate directory and file
by kcott (Archbishop) on Sep 14, 2012 at 07:41 UTC

    G'day Divakar,

    The built-in module File::Spec has a number of functions for manipulating pathnames: splitpath() would be the one to use here.

    -- Ken

Re: How to seperate directory and file
by ramesh824 (Initiate) on Sep 14, 2012 at 07:18 UTC
    You can use basename and dirname functions from "File::Basename" CPAN module to achieve this.
Re: How to seperate directory and file
by Anonymous Monk on Sep 14, 2012 at 08:22 UTC
    $ perl -E " use Path::Class; my $path = file(q[/ro/sham/bo.foo]); say +$path->parent; say $path->basename; " \ro\sham bo.foo