Jürgen Exner said:
Of course it works, it's just not very useful.
It doesn't work if $dir does not contain any shell meta-characters.
In that case, perl will bypass the shell and try to find 'pushd' in
$ENV{PATH} itself. This fails, because 'pushd' is a shell built-in
and does not exist in $ENV{PATH}.
The situation is different for the 'cd' command (at least, on Posix-
compliant systems). 'Cd' is also a shell built-in (it has to be), but
it also exists as a binary in /usr/bin/. The authors of the Posix
standard felt that script writers might want to know if they could do
chdir($dir) if they wanted to. The Perl way to do this, would be to
try it and look at the value returned by the chdir() command.
Posix provides an alternative: you can do system("cd $dir"). This
will create a new process. This new process will try to do chdir($dir).
If this succeeds, $? is set 0 in the parent process, else it's set to a
non-zero value.
Hope this helps,
-- HansM