1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#!/usr/bin/perl
use strict;
# Takes directories on stdin and puts a list on stdout where any directory
# that has another directory as it's stem is removed
# so if you have /a/b and /a/b/c then /a/b/c is removed
my @arr;
while(<STDIN>)
{
chomp;
# strip "" and "/" to avoid problems
if(length($_) >1)
{
push(@arr, $_);
}
}
for(my $i = 0; $i <= $#arr; $i++)
{
print "$arr[$i]\n";
my $stem = $arr[$i] . "/";
my $stemlen = length($arr[$i]) + 1;
while ($i + 1 <= $#arr and $stem eq substr($arr[$i + 1], 0, $stemlen))
{
splice(@arr, $i + 1, 1);
}
}
|