Perl脚本:列出目录下所有的文件扩展名(后缀名)

前端之家收集整理的这篇文章主要介绍了Perl脚本:列出目录下所有的文件扩展名(后缀名)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
 

#!/bin/perl
# Extension_filename_lister v0.1
# List all extension filenames without duplicate in a directory.

use strict;
use warnings;
use File::Find;

my %extname_list;

sub process_file {
    my $cur_file = $_; 

    # Ignore the directories . and ..
    if ($cur_file eq "." || $cur_file eq "..") {
        return;
    }

    (my $ext_name) = ($cur_file =~ /\.(\w+)$/);

    if (defined ($ext_name)) {
        $extname_list{$ext_name} = "Yes";
    }

#    print $cur_file,"\n";
#    print $ext_name,"\n";
}

my @DIRLIST = ("."); 
find(\&process_file,@DIRLIST);

print "Extension filenames:\n"; foreach my $item (keys %extname_list) {     print $item,"\n"; }

猜你在找的Perl相关文章