473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 9423
numberwhun
3,509 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,509 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

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

Similar topics

5
by: Nicholas Geraldi | last post by:
I have a script that uses the chdir() function. I know the script works ( works perfectly on my host ), but when I put the script on my server here at work I get the following error. Warning:...
5
by: Premshree Pillai | last post by:
Hello, I recently wrote a Perl version of pyAlbum.py -- a Python script to create an image album from a given directory -- plAlbum.pl . It made me realize how easy-to-use Python is. ...
3
by: lonelyplanet999 | last post by:
Hi, I'm a newbie to perl and is now studying about perl programming, I read some perl programming tutorials online (enter 'Perl tutorial' at google.com) and also find some sample perl scripts...
10
by: Hendry Taylor | last post by:
I wrote a perl script and tested it on windows and it works fine. I then moved it onto a solaris machine and now it says that there is a syntax error with the following line of code: $user1 =...
3
by: dannycolligan | last post by:
I have a strange problem with os.chdir... here is my script that I am using to edit the filenames of my music library: #!/usr/bin/python from os import * ...
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
0
by: Julien Biezemans | last post by:
Hi everyone, I've written a file:// scheme stream wrapper that acts like chroot() (but is more flexible, does not require root privileges and works on any platform). Everything works just fine...
1
by: georgewa | last post by:
Greetings all, great forum, this is my first post. Recently trying to write a script that is designed to move files based on timestamps. I am fairly new to Perl, so please bare with me. I have...
10
by: ashootoshverma | last post by:
Hi Everyone, I am new in perl programming can anyone help me to give a right way to do in this program "Zip all .* file from a one windows directory to another directory." Here is my code. ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.