diff options
author | Larry Wall <lwall@jpl-devvax.jpl.nasa.gov> | 1990-08-08 17:07:07 +0000 |
---|---|---|
committer | Larry Wall <lwall@jpl-devvax.jpl.nasa.gov> | 1990-08-08 17:07:07 +0000 |
commit | 00bf170e31343ccc4fac7a63f6a3acf5e76c3616 (patch) | |
tree | 64f2ca6ce7de08a6bae7fb4d11de65e8d49396be /lib/pwd.pl | |
parent | 33b78306b8a6f9a33cf09697c8c3167d2111ea12 (diff) | |
download | perl-00bf170e31343ccc4fac7a63f6a3acf5e76c3616.tar.gz |
perl 3.0 patch #25 patch #19, continued
See patch #19.
Diffstat (limited to 'lib/pwd.pl')
-rw-r--r-- | lib/pwd.pl | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/pwd.pl b/lib/pwd.pl new file mode 100644 index 0000000000..c141e9888e --- /dev/null +++ b/lib/pwd.pl @@ -0,0 +1,48 @@ +;# pwd.pl - keeps track of current working directory in PWD environment var +;# +;# $Header: pwd.pl,v 3.0.1.1 90/08/09 04:01:24 lwall Locked $ +;# +;# $Log: pwd.pl,v $ +;# Revision 3.0.1.1 90/08/09 04:01:24 lwall +;# patch19: Initial revision +;# +;# +;# Usage: +;# require "pwd.pl"; +;# &initpwd; +;# ... +;# &chdir($newdir); + +package pwd; + +sub main'initpwd { + if ($ENV{'PWD'}) { + local($dd,$di) = stat('.'); + local($pd,$pi) = stat($ENV{'PWD'}); + return if $di == $pi && $dd == $pd; + } + chop($ENV{'PWD'} = `pwd`); +} + +sub main'chdir { + local($newdir) = shift; + if (chdir $newdir) { + if ($newdir =~ m#^/#) { + $ENV{'PWD'} = $newdir; + } + else { + local(@curdir) = split(m#/#,$ENV{'PWD'}); + @curdir = '' unless @curdir; + foreach $component (split(m#/#, $newdir)) { + next if $component eq '.'; + pop(@curdir),next if $component eq '..'; + push(@curdir,$component); + } + $ENV{'PWD'} = join('/',@curdir) || '/'; + } + } + else { + 0; + } +} + |