Skip to content

Instantly share code, notes, and snippets.

@jasoncodes
Created January 24, 2017 09:47
Show Gist options
  • Save jasoncodes/c28ac3d6cce622927cd5a38f35357c45 to your computer and use it in GitHub Desktop.
Save jasoncodes/c28ac3d6cce622927cd5a38f35357c45 to your computer and use it in GitHub Desktop.
#!/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