in reply to Re: 2 substitution problems
in thread Yet another substitution problem
Purely as a mental exercise, a deprecated regex approach to handling repeated return to a parental directory might be something like:
However, this falls into the class of Stupid Regex Tricks because:>perl -wMstrict -le "my $parent = qr{ \.\. / }xms; my $dir = qr{ (?> [^/]+ /) (?<! $parent) }xms; print 'output:'; for my $f (@ARGV) { 1 while $f =~ s{ $dir $parent }{}xmsg; print $f } " /vobs/foo/../foo/bar/me/my/../../me/my/moo /vobs/foo/../bar/me/my/../../ma/mo/moo /vobs/x/y/z/../../../x/y/z/filename /vobs/x/y/z/../../../a/b/c/filename /a/../b/c/d/../../e/f/g/h/i/../../../j/k/l/m/n/o/p/../../../../q output: /vobs/foo/bar/me/my/moo /vobs/bar/ma/mo/moo /vobs/x/y/z/filename /vobs/a/b/c/filename /b/e/f/j/k/l/q
As Amphiaraus said, the preferred solution would be some module like Cwd that would overcome all these objections.
Update: Added symlink objection to list of regex solution objections per parv.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: 2 substitution problems
by parv (Parson) on Mar 28, 2009 at 16:24 UTC | |
by AnomalousMonk (Archbishop) on Mar 28, 2009 at 22:11 UTC | |
by parv (Parson) on Mar 29, 2009 at 03:04 UTC |