Hi

I agree that the code has some flaws in that.

Infact immediately after posting my solution, I thought of your test case
only.

If I will get some time, I will work on the same and let you know.

Thanks for the feedback.

Regards,
Amit Saxena

On Wed, Jul 2, 2008 at 8:08 PM, Chen Yue <[EMAIL PROTECTED]> wrote:

>
>
>
>
> Hi Amit
>
>
>
> The code really works but with a tiny flaw.
>
>
>
> If the path is "/a/b/../../c", the result would be "/a/../c" rather than
> "/c". So I need to loop to clean up the dot-dot if tied up
>
>
>
> Thank you for the suggestion
>
>
>
> Hi
>
>
> The code would be something like this :-
>
> [root@ ~]# cat t.pl
> #!/usr/bin/perl
>
> $str = "/a/b/./c/../d";
>
> $str1 = $str;
>
> print "\nstr = [$str]";
> print "\nstr1 = [$str1]";
> print "\n---------------------------------------------------";
>
> $str1 =~ s/([^\/]+)\/\.\.\/([^\/]+)/$2/g;
>
> print "\nstr = [$str]";
> print "\nstr1 = [$str1]";
> print "\n---------------------------------------------------";
>
> $str1 =~ s/\.\/([^\/]+)/$1/g;
>
> print "\nstr = [$str]";
> print "\nstr1 = [$str1]";
> print "\n---------------------------------------------------";
>
> print "\nHave a nice day !!!\n";
>
> [root@ ~]# perl t.pl
>
> str = [/a/b/./c/../d]
> str1 = [/a/b/./c/../d]
> ---------------------------------------------------
> str = [/a/b/./c/../d]
> str1 = [/a/b/./d]
> ---------------------------------------------------
> str = [/a/b/./c/../d]
> str1 = [/a/b/d]
> ---------------------------------------------------
>
> Have a nice day !!!
>
> Regards,
> Amit Saxena
>
> On Wed, Jul 2, 2008 at 7:03 PM, Chen Yue <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> I have a file containing UNIX-styled Path in each line. But the path is
> simplified enough. Some of them has ".." and "." in the middle, such as
> "/a/b/./c/../d".
> Now I want to simplify each Path according to Unix tradition.
>
> /a/b/./c/../d    ->    /a/b/d
>
> The only way I could think out is to split the path and reconstruct them in
> reverse order. But I don't think it is a smart solution. Is there a quick
> way to employ regexp or a library to fix this?
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

Reply via email to