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