Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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

Replies are listed 'Best First'.
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 (Bishop) 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?
[Corion]: It's an older meme, but it checks out sir!

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2017-03-27 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (321 votes). Check out past polls.