On Jul 3, 4:38 pm, [EMAIL PROTECTED] (Rob Dixon) wrote:
> > Pardon me for being dense, but I can't figure out a case where
>
> >> if ($path[-1] eq '..') {
>
> > would ever be true.
>
> My intention was to preserve relative paths starting with '..', but I got it
> wrong. Here's V2.
>
> Rob
>
>
Brad Baxter wrote:
> On Jul 2, 11:46 am, [EMAIL PROTECTED] (Rob Dixon) wrote:
>> This seems to do the job. Hope it helps.
>>
>> Rob
>>
>> sub canonical_path {
>>
>> my $path = shift;
>> my @path;
>>
>> foreach (File::Spec->splitdir($path)) {
>> if ($_ eq '..') {
>> if ($path[-1] eq
On Jul 2, 11:46 am, [EMAIL PROTECTED] (Rob Dixon) wrote:
>
> This seems to do the job. Hope it helps.
>
> Rob
>
> sub canonical_path {
>
> my $path = shift;
> my @path;
>
> foreach (File::Spec->splitdir($path)) {
> if ($_ eq '..') {
> if ($path[-1] eq '..') {
> push @path, $
John W. Krahn wrote:
> John W. Krahn wrote:
>> Chen Yue wrote:
>>
>>> 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
>>> trad
John W. Krahn wrote:
Chen Yue wrote:
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
T
Chen Yue wrote:
Hi
Hello,
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 w
Chen Yue wrote:
>
> Rob Dixon wrote:
>>
>> Chen Yue wrote:
>>>
>>> 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 traditi
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 PR
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.p
Hi Peter
Actually, I don't want to translate the path into realpath because some of
the paths even do not exist on the host. What I need is just a simplified
format.
Anyway, thank you for the advice.
On Wed, 02 Jul 2008 21:33:59 +0800, Chen Yue wrote:
> I have a file containing UNIX-styled Path
Hi Rob
Thank you for the suggestion. Actually, abs_path requires the original path
exists on the host. But my case does not fulfill this. This is what puzzled
me.
Sent: Wednesday, July 02, 2008 9:58 PM
To: beginners@perl.org
Cc: Chen Yue
Subject: Re: simplify a path
Chen Yue wrote:
>
On Wed, 02 Jul 2008 21:33:59 +0800, Chen Yue wrote:
> 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/.
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 = [$st
Chen Yue wrote:
>
> 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
On Wed, Jul 2, 2008 at 9:33 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 trad
15 matches
Mail list logo