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

suneel.reddy has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Can anyone help me in finding the parent directory path, I don't have any inputs for current directory also. I just need to find the parent directory path from where my script is

I also have a script which only prints parent directory, where as I need to store it into a variable,

---------------------------------------

use strict;

use warnings;

use Cwd;

use File::Spec;

print Cwd::realpath(File::Spec->updir);

---------------------------------------

Thanks in advance

Suneel

Replies are listed 'Best First'.
Re: Reading parent directory path
by Corion (Patriarch) on Sep 17, 2012 at 11:07 UTC

    Have you thought about storing the value in a variable instead of printing it?

    Also, reading the File::Spec documentation might help you in understanding what function calls to combine to get the results you want.

    I'm sure your course material covers all of this. I suggest you review your notes.

Re: Reading parent directory path
by marto (Cardinal) on Sep 17, 2012 at 11:07 UTC

    Assign this to a variable if it prints what you want.

    use strict; use warnings; use Cwd; use File::Spec; my $parent = Cwd::realpath(File::Spec->updir); print "Parent directory: $parent";