本帖最后由 523066680 于 2017-1-18 21:39 编辑
- =info
- Code by 523066680@163.com
- =cut
-
- # 备注,可能遇到 Unicode 文件名路径,
- # 暂时使用系统 cmd /U /c dir 生成路径列表
-
- use Encode;
- use IO::Handle;
- use Data::Dump qw/dump dd/;
-
- our $hash = {};
- my $gstr;
-
- {
- local $/ = "\x0d\x00\x0a\x00";
-
- print "getting file lists ...\n";
- @files = `cmd /U /c dir /s /b C:\\MinGW`;
-
- print "Deal ...\n";
- for my $n ( 0 .. $#files )
- {
- $files[$n] =~s/\x0d\x00\x0a\x00//;
- $gstr = encode('gbk', decode('utf16-le', $files[$n]));
- toStruct( $gstr );
- }
- }
-
- #举个栗子
- dd( $hash->{'C:'}{'MinGW'}{'include'}{'boost'}{'accumulators'} );
-
- sub toStruct
- {
- my $path = shift;
- my @parts = split(/[\/\\]/, $path);
- my $ref;
- $ref = $hash;
-
- grep
- {
- $ref->{$_} = {} unless ( exists $ref->{$_} );
- $ref = $ref->{$_};
- }
- @parts;
- }
复制代码 部分 Dump 结果- getting file lists ...
- Deal ...
- {
- "accumulators.hpp" => {},
- "accumulators_fwd.hpp" => {},
- "framework" => {
- "accumulator_base.hpp" => {},
- "accumulator_concept.hpp" => {},
- "accumulator_set.hpp" => {},
- "accumulators" => {
- "droppable_accumulator.hpp" => {},
- "external_accumulator.hpp" => {},
- "reference_accumulator.hpp" => {},
- "value_accumulator.hpp" => {},
- },
- "depends_on.hpp" => {},
- "external.hpp" => {},
- "extractor.hpp" => {},
- "features.hpp" => {},
- "parameters" => {
- "accumulator.hpp" => {},
- "sample.hpp" => {},
- "weight.hpp" => {},
- "weights.hpp" => {},
- },
- },
- "numeric" => {
- "detail" => {
- "function1.hpp" => {},
- "function2.hpp" => {},
- "function3.hpp" => {},
- "function4.hpp" => {},
- "function_n.hpp" => {},
- "pod_singleton.hpp" => {},
- },
- "functional" => { "complex.hpp" => {}, "valarray.hpp" => {}, "vector.hpp" => {} },
- "functional.hpp" => {},
- "functional_fwd.hpp" => {},
- },
复制代码 对于文件/目录辨别、符号链接(symbolic link)判断、文件大小等属性的提取,Perl 也不太合适,
还是 C 实在,从根本解决问题,已经写了一部分功能 |