Unless the OP made a mistake, he did not include helloworld/ in his definition of a terminal directory, thus your solution doesn't quite work, but I'll bet you can tweak it so it will work!
| [reply] [d/l] |
Unless the OP made a mistake, he did not include helloworld/ in his definition of a terminal directory, thus your solution doesn't quite work, but I'll bet you can tweak it so it will work! i don't like your phrasing , to which i say, can't you do it?
yeah, none of the solutions filter out the parents of terminals, so with help from Re^4: Want for a name? (between)
#!/usr/bin/perl --
use strict;
use warnings;
sub mapAdj(&$@) {
use vars qw/ $a $b $c $d $e $f $g $h $i $j /;
local( $a, $b, $c, $d, $e, $f, $g, $h, $i, $j );
my( $code, $n ) = ( shift, shift );
map $code->(
($a, $b, $c, $d, $e, $f, $g, $h, $i, $j ) = @_[ $_-$n .. $_ ]
), --$n .. $#_;
}
sub subsumes { return 0 == index $_[1], $_[0]; }
my $termies = "
a/
a/b/
a/b/t/
a/b/t/f
a/c/
a/c/d/
a/c/d/t/
a/c/d/t/f
t/
";
open my($fh),'<',\$termies;
my @terminals;
while(<$fh>){
chomp;
push @terminals, $_ if m{/\s*$}sm;
}
@terminals = mapAdj { subsumes($a,$b) ? ( ) : ( $a ) } 2, (sort @termi
+nals), '';
print "$_\n" for @terminals;
__END__
a/b/t/
a/c/d/t/
t/
| [reply] [d/l] |