- 论坛徽章:
- 0
|
本帖最后由 黑色阳光_cu 于 2010-05-28 22:00 编辑
- #!/bin/env perl
- use strict;
- use warnings;
- my $root = {_path => undef};
- while (defined(my $path = <DATA>))
- {
- chomp($path);
- my @fields = split(/\\+/, $path);
- my $prefix = $root;
- for (my $n = 0; $n <= $#fields; $n++)
- {
- if (not exists $prefix->{$fields[$n]})
- {
- $prefix->{$fields[$n]} = {_path => $path};
- }
-
- $prefix = $prefix->{$fields[$n]};
- }
- }
- my @deep_path = &find_deep_path($root);
- print join("\n", @deep_path);
- ####################################################################################
- sub find_deep_path
- {
- my ($root) = @_;
- my @deep_path;
- if (scalar(keys(%{$root})) == 1)
- {
- push(@deep_path, $root->{_path});
- }
- else
- {
- delete $root->{_path};
- foreach my $child (keys(%{$root}))
- {
- push(@deep_path, &find_deep_path($root->{$child}));
- }
- }
- return @deep_path;
- }
- __DATA__
- D:\Temp\test
- D:\Temp\test1
- D:\Temp\test2
- D:\Temp\test\a
- D:\Temp\test\b
- D:\Temp\test1\aaa
- D:\Temp\test1\bbb
- D:\Temp\test1\aaa\aadf
- D:\Temp\test1\bbb\aaa
- D:\Temp\test2\ad
- D:\Temp\test2\23
- D:\Temp\test2\23\a32
复制代码 |
|