home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
unixtool.zip
/
TOOLS
/
lib
/
perl
/
pwd.pl
< prev
next >
Wrap
Perl Script
|
2000-04-21
|
811b
|
43 lines
# -*- Perl -*-
eval "exec /usr/local/bin/perl -S $0 $*"
if $running_under_some_shell;
;# pwd.pl - keeps track of current working directory in PWD environment var
;#
;# $Id: pwd.pl,v 1.2 1996/07/29 21:20:20 jfk Exp $
;#
;# Usage:
;# require "pwd.pl";
;# &initpwd;
;# ...
;# &chdir($newdir);
package pwd;
sub main'initpwd {
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;
}
}
1;