Home / Software / Computer programming / Perl help with chdir in WinXp
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Perl help with chdir in WinXp  (Read 511 times)
acidblue
Topic Starter
Rookie



Posts: 13


« on: July 29, 2010, 10:25:27 PM »

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.
IP logged
BC_Programmer
Mastermind


Thanked: 697
Posts: 15,874

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #1 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";

IP logged

My Blog

BASeBlock 2.3.0 (NOW WITH MACGUFFINS!)
acidblue
Topic Starter
Rookie



Posts: 13


« Reply #2 on: July 29, 2010, 11:53:11 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.  ;D

I really like the last one:
Code: [Select]
use File::HomeDir;


$path=home()."\\dir1\\dir2";
IP logged
Pages: [1] - (Top) Print 
Home / Software / Computer programming / Perl help with chdir in WinXp « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.084 seconds with 20 queries.