I don't understand why you don't want C:\\c and c:\\car in your result list. From your explanation, I think your nested hash approach is an elegant solution. I have another solution that relies on the fact that a subdirectory will always sort at a later place than its parent:
use strict; my @paths = ( 'C:\\foo\\bar\\baz', 'C:\\foo\\bar', 'C:\\car', 'C:\\c' ); my $last = ""; my @nested; for (sort @paths) { if (not @nested) { push @nested, $_; } elsif (/^\Q$nested[-1]\E\\/i) { $nested[-1] = $_; } else { push @nested, $_; }; }; print "$_\n" for @nested;
On Windows, we have a case-insensitive file system, so we want to compare case-insensitive. This will possibly fail if you have umlauts in your directory names that should collate to the same character.
In reply to Re: Finding nested directories from a string list.
by Corion
in thread Finding nested directories from a string list.
by superfrink
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |