Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Reading parent directory path

by suneel.reddy (Novice)
on Sep 17, 2012 at 10:46 UTC ( #994006=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on Reading parent directory path
Re: Reading parent directory path
by Corion (Pope) 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 (Chancellor) 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";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994006]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-04-19 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls