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

Is there a Windows equivalent to the cwd module? When I am using the Perl interpreter in Strawberry Perl, it barfs up when I use cwd in a Perl script. For example:
#!/usr/bin/env perl use cwd; my $dirname; $dirname = cwd(); print "$dirname\n";

Replies are listed 'Best First'.
Re: cwd module
by Corion (Patriarch) on Apr 10, 2008 at 15:58 UTC

    Your code will barf all the same on Unix. The module is called Cwd (note the upper case C), and it is in the Perl core and available on both, Unix and Windows..

      Oops. Sorry about that. Tried it "Cwd". It worked.
      No, it barfs differently on Unix, since the import part of use silently fails instead of use itself failing.

        "All the same" is synonymous with "also," (update: or "anyway") not "in the same way." So, though it's as fuzzy as colloquial language often is, it doesn't contradict what you're saying.

Re: cwd module
by jplindstrom (Monsignor) on Apr 10, 2008 at 22:31 UTC
    May I recommend File::chdir (yes, note the case :), which makes it simple to not just get the current dir, but also to change dir. And restore it later by just doing

    local $CWD = $new_dir;.

    /J