I have two strings: $dir1
and $dir2
. I want to use chdir
as shown below:
chdir "/home/$dir1/$dir2";
when I try this it doesn't change the directory. I checked the current working directory same as before
Is there any way to do this?
I have two strings: $dir1
and $dir2
. I want to use chdir
as shown below:
chdir "/home/$dir1/$dir2";
when I try this it doesn't change the directory. I checked the current working directory same as before
Is there any way to do this?
Typically I write that as:
use v5.10;
use File::Spec::Functions;
my $dir = catfile( '/home', $dir1, $dir2 );
die "Dir <$dir> isn't a directory or doesn't exist" unless -e -d $dir;
chdir $dir or die "Could not change to <$dir>: $!";
Whenever you do something with the system, check the results to ensure it happened.
And, curiously, I didn't realize that Pearson's sample chapter of my book Effective Perl Programming is the one that covers stacked file test operators.