Print base of each directory subtree specified in the unsorted input list.
[nethome.git] / bin / dirlistbases
diff --git a/bin/dirlistbases b/bin/dirlistbases
new file mode 100755 (executable)
index 0000000..d89c5d2
--- /dev/null
@@ -0,0 +1,36 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+
+my $tree;
+LINE: while (<>) {
+       chomp;
+       my $base=\$tree;
+       warn($_),next if !s#^/##;
+       warn($_),next if m#//#;
+       warn($_),next if m#/$#;
+       for (split qr#/#) {
+               next LINE if ${$base}->{""};
+               $base=\(${$base}->{$_});
+               }
+       ${$base}->{""}=1;
+       }
+#use Data::Dumper;
+#print Dumper $tree;
+
+sub out($$);
+sub out($$)
+{
+my($base,$where)=@_;
+
+       if ($base->{""}) {
+               print $where."\n";
+               return;
+               }
+       for (sort keys(%$base)) {
+               next if $_ eq "";
+               out($base->{$_},"$where/$_");
+               }
+}
+
+out($tree,"");