Computer Hope
Software => Computer programming => Topic started by: acidblue on July 29, 2010, 10:25:27 PM
-
In C, you can use '%usrename%' when changing directories.
Like this:
$path = "C:\\documents\\%username%\\dir1\\dir2";
Does Perl have something like that??
I want to be able to change directories with out having to type code for every user name.
-
use the $ENV hashtable...
$path = "C:\\documents\\".$ENV{USERNAME}."\\dir1\\dir2";
or, you could use USERPROFILE instead, which will work more readily across windows versions.
$path= $ENV{USERPROFILE}."\\dir1\\dir2";
Or, you could make a more generic cross platform solution by using FILE::HOMEDIR, and dump environment variables altogether...
use File::HomeDir;
$path=home()."\\dir1\\dir2";
-
use the $ENV hashtable...
$path = "C:\\documents\\".$ENV{USERNAME}."\\dir1\\dir2";
or, you could use USERPROFILE instead, which will work more readily across windows versions.
$path= $ENV{USERPROFILE}."\\dir1\\dir2";
Or, you could make a more generic cross platform solution by using FILE::HOMEDIR, and dump environment variables altogether...
use File::HomeDir;
$path=home()."\\dir1\\dir2";
Thanks BC_, thats just what I needed. ;D
I really like the last one:
use File::HomeDir;
$path=home()."\\dir1\\dir2";