|
Perl: Run perl script in the current process
I have a question regarding running perl in the current process.
I shall demonstrate with an example.
Look at this.
Code:
sh-2.05b$ pwd
/tmp
sh-2.05b$ cat test.sh
#! /bin/sh
cd /etc
sh-2.05b$ ./test.sh
sh-2.05b$ pwd
/tmp
sh-2.05b$ . ./test.sh
sh-2.05b$ pwd
/etc
sh-2.05b$
So invoking ./test.sh spawns a sub-shell and runs the script. Whereas . ./test.sh will run the script in the current shell.
Now, how can I simulate the latter behavior with a perl script. I tried the following but it did not help.
Code:
sh-2.05b$ pwd
/tmp
sh-2.05b$ cat test.pl
#! /usr/bin/perl
chdir("/etc");
sh-2.05b$ ./test.pl
sh-2.05b$ pwd
/tmp
sh-2.05b$ . ./test.pl
sh: ./test.pl: line 2: syntax error near unexpected token `"/tmp"'
sh: ./test.pl: line 2: `chdir("/tmp");'
sh-2.05b$
Is there any other way of running the script to make sure that the changes made by the script will affect the current process ?
Thanks,
Vino
|