|
Answer» In C, you can use '%usrename%' when changing directories. Like this: Code: [Select]$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...
Code: [Select]$path = "C:\\documents\\".$ENV{USERNAME}."\\dir1\\dir2";
or, you could use USERPROFILE instead, which will WORK more readily across windows versions.
Code: [Select]$path= $ENV{USERPROFILE}."\\dir1\\dir2";
Or, you could make a more generic cross platform SOLUTION by using FILE::HOMEDIR, and DUMP environment variables altogether...
Code: [Select]use File::HomeDir; $path=home()."\\dir1\\dir2";
Quote from: BC_Programmer on July 29, 2010, 10:40:16 PM use the $ENV hashtable...
Code: [Select]$path = "C:\\documents\\".$ENV{USERNAME}."\\dir1\\dir2";
or, you could use USERPROFILE instead, which will work more readily across windows versions.
Code: [Select]$path= $ENV{USERPROFILE}."\\dir1\\dir2";
Or, you could make a more generic cross platform solution by using FILE::HOMEDIR, and dump environment variables altogether...
Code: [Select]use File::HomeDir; $path=home()."\\dir1\\dir2";
Thanks BC_, thats just what I needed.
I REALLY like the last one: Code: [Select]use File::HomeDir;
$path=home()."\\dir1\\dir2";
|