How to ignore the single and double dot entries in Perl's readdir?

后端 未结 5 892
甜味超标
甜味超标 2021-01-21 05:04

Following up from here: Perl Imgsize not working in loop? I have another question - how do I not let perl list the single and double dot entries when it reads the files in a dir

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 05:36

    If you're getting the directory contents in list context, you can use grep to filter out the dotfiles:

    opendir (my $dh, $src) || die "Can't opendir $src: $!\n";
    my @entries = grep {!/^\./} readdir($dh);
    closedir ($dh);
    

提交回复
热议问题