use strict; use warnings; use Cwd; use File::Spec; use Test::More 'no_plan'; use File::pushd qw( pushd ); # Meditation benefits from short directory names, so save our initial # directory then switch to the tempdir and create a dummy directory my $initial_dir = cwd(); chdir File::Spec->tmpdir(); mkdir "t" unless -e "t"; # Record the directory before pushd() is called my $original_dir = cwd(); # Establish a limited scope for pushd() { # Change to target directory until $new_dir goes out of scope # Returns absolute path to new directory my $new_dir = pushd( 't' ); is( cwd(), $new_dir, "changed to new directory" ); } is( cwd(), $original_dir, "changed back to original directory" ); # Get back to the starting point chdir $initial_dir;