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

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

概述  #!/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 $c  

#!/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脚本列出目录下所有的文件扩展名(后缀名)全部内容,希望文章能够帮你解决Perl脚本:列出目录下所有的文件扩展名(后缀名)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1286367.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存