change directory in perl

B

bebe

I have a perl script which is used to change to new_directory. I
used "chdir". It seems working and I also work to have the directory
changed to new_directory when exit this perl script. How do I do this
in perl.


$new_dir = "/home/otherDir";
chdir ("$new_dir");
 
X

xhoster

bebe said:
I have a perl script which is used to change to new_directory. I
used "chdir". It seems working and I also work to have the directory
changed to new_directory when exit this perl script. How do I do this
in perl.

$new_dir = "/home/otherDir";
chdir ("$new_dir");

This is a FAQ.

perldoc -q directory:

I {changed directory, modified my environment} in a perl script.
How come the change disappeared when I exited the script? How do I
get my changes to be visible?

Unix
In the strictest sense, it can't be done--the script executes as
a different process from the shell it was started from. Changes
to a process are not reflected in its parent--only in any
children created after the change. There is shell magic that
may allow you to fake it by eval()ing the script's output in
your shell; check out the comp.unix.questions FAQ for details.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
M

Martijn Lievaart

I have a perl script which is used to change to new_directory. I used
"chdir". It seems working and I also work to have the directory changed
to new_directory when exit this perl script. How do I do this in perl.


$new_dir = "/home/otherDir";
chdir ("$new_dir");

perldoc -q changed directory

HTH,
M4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top