How can I list files under a directory with a specific name pattern using Perl?

后端 未结 6 883
长发绾君心
长发绾君心 2021-01-07 12:15

I have a directory /var/spool and inside that, directories named

a  b  c  d  e  f  g  h i  j  k  l  m  n  o  p q  r  s  t  u  v  x  y z

An

6条回答
  •  不要未来只要你来
    2021-01-07 12:51

    As others have noted, use File::Find:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use File::Find;
    
    find(\&find_emails => '/var/spool');
    
    sub find_emails {
        return unless /\A[0-9]+[.]\z/;
        return unless -f $File::Find::name;
    
        process_an_email($File::Find::name);
        return;
    }
    
    sub process_an_email {
        my ($file) = @_;
        print "Processing '$file'\n";
    }
    

提交回复
热议问题