On Fri, 13 Dec 2002, Clayton, Nik [IT] wrote: > > I have a path, say "dira/dirb/../dirc/file" and I want to > > collapse it to a canonical path "dira/dirc/file". > > You could always cheat. > > use Cwd; > > sub canon_path { > my $path = shift; > my $old_wd = cwd(); > chdir $path; > my $cpath = cwd(); > chdir $old_cwd; > return $cpath; > }
Assuming you aren't using a virtual root, which is the point. Also if you look at how cwd() works internally (in libc), it isn't pretty. S. > Sprinkle with error checking for things like non-existent directories, > or directories you can't chdir into as necessary. > > N > -- Shevek I am the Borg. sub AUTOLOAD{my$i=$AUTOLOAD;my$x=shift;$i=~s/^.*://;print"$x\n";eval qq{*$AUTOLOAD=sub{my\$x=shift;return unless \$x%$i;&{$x}(\$x);};};} foreach my $i (3..65535) { &{'2'}($i); }