in reply to local scoped cwd

#!/opt/perl/bin/perl -w use strict; sub TIESCALAR {chomp (my $cwd = `pwd`); bless \$cwd => shift} sub FETCH {${$_[0]}} sub STORE {chdir $_[1] or die; ${$_[0]} = $_[1]} use vars qw /$cwd/; tie $cwd => 'main';
Now you can just assign to $cwd to change directories, and when you localize it, it will restore the directory when the value goes out of scope.

-- Abigail

Replies are listed 'Best First'.
Re (tilly) 1: local scoped cwd
by tilly (Archbishop) on Jun 27, 2001 at 12:09 UTC
    Non-Unix users take note. You can use the Cwd module instead of chomping `pwd` to make the above portable.

    That said I think the above tie implementation would be a nice addition to the Cwd module.

    UPDATE
    Shouldn't the FETCH method return the real cwd and not just the last thing it was set to through the tied variable?