in reply to How do I change .. to the real filename?
... will eat the last directory name that's up'ed by the trailing ..$file =~ s%/[^/]+/\.\.$%%
We need the itterations of each loop as each substitution may reveal additional matchs.# colapse /./ and /.$ 1 while ($file =~ s%/\.(/|$)%$1%g); # colapse /dir/../ and /dir/..$ # ignore /../../ and /../..$ 1 while ($file =~ s%/[^/]+/(?<!/\.\./)\.\.(/|$)%$1%g); # remove ^dir/../ and ^dir/../ # ignore ^../../ and ^../.. 1 while ($file =~ s%^[^/]+/(?<!^\.\./)\.\.(/|$)%%); # colapse ^/../ to / 1 while ($file =~ s%^/\.\./%/%); # expand null to . $file =~ s%^$%.%;
|
|---|