Created
January 24, 2017 09:47
-
-
Save jasoncodes/c28ac3d6cce622927cd5a38f35357c45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings FATAL => 'all'; | |
{ | |
package pushd; | |
use Cwd qw(getcwd chdir); | |
sub new { | |
my ($class, $new_dir) = @_; | |
my $old_dir = getcwd(); | |
chdir($new_dir) or die "$!"; | |
my $self = bless { | |
old_dir => $old_dir, | |
}, $class; | |
return $self; | |
} | |
sub DESTROY { | |
my $self = shift; | |
chdir($self->{old_dir}) or die "$!"; | |
} | |
} | |
print `pwd`; | |
{ | |
my $pushd = pushd->new('/tmp'); | |
print `pwd`; | |
} | |
print `pwd`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment