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.
6 # This legacy library is deprecated and will be removed in a future
9 # In particular, this should not be used as an example of modern Perl
10 # programming techniques.
12 # Suggested alternative: Cwd
14 warn( "The 'pwd.pl' legacy library is deprecated and will be"
15 . " removed in the next major release of perl. Please use the"
16 . " Cwd module instead." );
18 ;# $RCSfile: pwd.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:11 $
32 local($dd,$di) = stat('.');
33 local($pd,$pi) = stat($ENV{'PWD'});
34 if (!defined $dd or !defined $pd or $di != $pi or $dd != $pd) {
35 chop($ENV{'PWD'} = `pwd`);
39 chop($ENV{'PWD'} = `pwd`);
41 if ($ENV{'PWD'} =~ m|(/[^/]+(/[^/]+/[^/]+))(.*)|) {
42 local($pd,$pi) = stat($2);
43 local($dd,$di) = stat($1);
44 if (defined $pd and defined $dd and $di == $pi and $dd == $pd) {
51 local($newdir) = shift;
52 $newdir =~ s|/{2,}|/|g;
54 if ($newdir =~ m#^/#) {
55 $ENV{'PWD'} = $newdir;
58 local(@curdir) = split(m#/#,$ENV{'PWD'});
59 @curdir = '' unless @curdir;
60 foreach $component (split(m#/#, $newdir)) {
61 next if $component eq '.';
62 pop(@curdir),next if $component eq '..';
63 push(@curdir,$component);
65 $ENV{'PWD'} = join('/',@curdir) || '/';