469,282 Members | 2,404 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Perl chdir problem

Hello,

I'm having a tough time using chdir in different versions of perl in a dos window (XP). In early versions of Perl 5.x it works just fine. I have a bat file that dynamically sets my perl path to either 5.0.x or to 5.8.8:

Expand|Select|Wrap|Line Numbers
  1. path %path%;c:\perl\[whichever]
  2.  
Then in I call the perl script which just has this:

Expand|Select|Wrap|Line Numbers
  1. $dirLocation ='c:\[whatever]';
  2.  
  3. chdir $dirLocation or die "Can't cd to $dirLocation: $!\n";
  4.  
  5.  
In the earlier version of perl it works fine and moves dos to that directory. In 5.8.8 it doesn't. But nor does it die. It just doesn't switch directories. I've confirmed that it's at least looking for a valid dir by changing $dirLocation to something nonexistent and it does indeed then balk. So what am I missing here???

Thanks for any help.

John
Nov 19 '07 #1
6 9088
numberwhun
3,503 Expert Mod 2GB
Hello,

I'm having a tough time using chdir in different versions of perl in a dos window (XP). In early versions of Perl 5.x it works just fine. I have a bat file that dynamically sets my perl path to either 5.0.x or to 5.8.8:

Expand|Select|Wrap|Line Numbers
  1. path %path%;c:\perl\[whichever]
  2.  
Then in I call the perl script which just has this:

Expand|Select|Wrap|Line Numbers
  1. $dirLocation ='c:\[whatever]';
  2.  
  3. chdir $dirLocation or die "Can't cd to $dirLocation: $!\n";
  4.  
  5.  
In the earlier version of perl it works fine and moves dos to that directory. In 5.8.8 it doesn't. But nor does it die. It just doesn't switch directories. I've confirmed that it's at least looking for a valid dir by changing $dirLocation to something nonexistent and it does indeed then balk. So what am I missing here???

Thanks for any help.

John
If I may ask, how do you know that it is not working, especially if you get no errors?

Regards,

Jeff
Nov 21 '07 #2
eggi
9
Hi,


Try:
chdir("$dirlocation");

, Mike
Nov 25 '07 #3
KevinADC
4,059 Expert 2GB
Hi,


Try:
chdir("$dirlocation");

, Mike
adding quotes around a single scalar will not help and should really never be done anyway. It's a bad habit to get into when writing perl programs.
Nov 26 '07 #4
If I may ask, how do you know that it is not working, especially if you get no errors?

Regards,

Jeff

Jeff, DOS should change to the directory specified in the perl command. In my case it doesn't. It just stays where it was before running the script. Thanks.
Dec 6 '07 #5
numberwhun
3,503 Expert Mod 2GB
Jeff, DOS should change to the directory specified in the perl command. In my case it doesn't. It just stays where it was before running the script. Thanks.
I would definitely go with eggi's suggestion of using the chdir() function to change the working directory and see if that works then.

Regards,

Jeff
Dec 6 '07 #6
Try using a forward slashes instead of a backward slashes
in your path.

Regards,
Sakurakun
Oct 10 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Nicholas Geraldi | last post: by
5 posts views Thread by Premshree Pillai | last post: by
3 posts views Thread by lonelyplanet999 | last post: by
10 posts views Thread by Hendry Taylor | last post: by
3 posts views Thread by dannycolligan | last post: by
4 posts views Thread by Ignoramus6539 | last post: by
reply views Thread by Julien Biezemans | last post: by
10 posts views Thread by ashootoshverma | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.