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

Hi every1

I tried to google for it but couldn't find anything usefull (surprisingly).
I know I can use chdir to go down to a deeper directory, but how can I do the opposite (go up 1 directory) ?
Do I need to do something with %ENV or is there a simpler way ?

Thx

Replies are listed 'Best First'.
Re: How to move up 1 directory ?
by chromatic (Archbishop) on Jun 05, 2011 at 01:24 UTC
    use File::Spec; chdir File::Spec->updir;

    There's nothing special about chdir. If you give it an absolute path, it'll attempt to change your current directory to that absolute path. If you give it a relative path, it'll attempt to change your current directory to that relative path. (The relative path for "parent of the current directory" is probably .., but if you want to be very cross-platform paranoid, use File::Spec.)

Re: How to move up 1 directory ?
by JavaFan (Canon) on Jun 05, 2011 at 01:23 UTC
    chdir ".." or die "Failed to go to parent directory: $!";
Re: How to move up 1 directory ?
by Anonymous Monk on Jun 05, 2011 at 03:34 UTC
    use Path::Class; use autodie qw' chdir '; warn dir->parent; chdir dir->parent; __END__ .. at - line 3.