1 ;# pwd.pl - keeps track of current working directory in PWD environment var
4 # This library is no longer being maintained, and is included for backward
5 # compatibility with Perl 4 programs which may require it.
7 # In particular, this should not be used as an example of modern Perl
8 # programming techniques.
10 # Suggested alternative: Cwd
12 ;# $RCSfile: pwd.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:11 $
26 local($dd,$di) = stat('.');
27 local($pd,$pi) = stat($ENV{'PWD
'});
28 if (!defined $dd or !defined $pd or $di != $pi or $dd != $pd) {
29 chop($ENV{'PWD
'} = `pwd`);
33 chop($ENV{'PWD
'} = `pwd`);
35 if ($ENV{'PWD
'} =~ m|(/[^/]+(/[^/]+/[^/]+))(.*)|) {
36 local($pd,$pi) = stat($2);
37 local($dd,$di) = stat($1);
38 if (defined $pd and defined $dd and $di == $pi and $dd == $pd) {
45 local($newdir) = shift;
46 $newdir =~ s
|/{2,}|/|g
;
48 if ($newdir =~ m
#^/#) {
49 $ENV{'PWD'} = $newdir;
52 local(@curdir) = split(m
#/#,$ENV{'PWD'});
53 @curdir = '' unless @curdir;
54 foreach $component (split(m
#/#, $newdir)) {
55 next if $component eq '.';
56 pop(@curdir),next if $component eq '..';
57 push(@curdir,$component);
59 $ENV{'PWD'} = join('/',@curdir) || '/';