in reply to Changing path to home directory

I don't have a Windows machine at the ready, but File::HomeDir should work on various platforms.

use File::HomeDir (); my $HOME = File::HomeDir->my_home; chdir $HOME or die "Couldn't chdir $HOME: $!";

Replies are listed 'Best First'.
Re^2: Changing path to home directory
by ww (Archbishop) on Mar 05, 2015 at 02:17 UTC

    Close!

    #!/usr/bin/perl use 5.018; use strict; use warnings; # 1118814 use Cwd; use File::HomeDir(); my $cwd = getcwd(); say "At Ln 12: \$cwd: $cwd"; my $HOME = File::HomeDir->my_home; chdir $HOME or die "Couldn't chdir $HOME: $!"; say "At Ln 18; \$HOME: $HOME"; $cwd = getcwd(); say "At Ln 21, \$cwd: $cwd"; =head Execution: C:\>D:\PMonks\1118814.pl At Ln 12: $cwd: C:/ At Ln 18; $HOME: C:\Users\ww At Ln 21, $cwd: C:/Users/ww =cut
      Only a remark: on windows be very carefull mixing the Perl's idea of cwd with the OS's one.
      Given you have a drive y: can you predicdt the output of the following command? ;=)
      c:\path> y: & cd c:\ & dir c: & cd c:\Windows & dir c: & dir \
      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Good to know it works, thanks for testing. In regards to the "Close!" I don't see the significant difference? (AFAIK backslashes are "more correct" on Windows since forward slashes usually but don't always work?)

        The slashes and backslashes in the =head Execution: section are artifacts of the Perl/Win32 interaction; they were NOT coded into the script.

        But s/Close!/Expanding upon the above:/ would have been better content for para 1.