ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
It works good for most cases but I had trouble with paths that start, for example, with ".." (like "../script.sh") then it gives me: Use of uninitialized value within @c in pattern match (m//).foreach my $path ("/a/b/c/d/../../../e" , "/a/../b/./c//d") { my @c= reverse split m@/@, $path; my @c_new; while (@c) { my $component= shift @c; next unless length($component); if ($component eq ".") { next; } if ($component eq "..") { my $i=0; while ($c[$i] =~ m/^\.{0,2}$/) { $i++ } splice(@c, $i, 1); next } push @c_new, $component; } print "/".join("/", reverse @c_new) ."\n"; }
|
|---|