スキップする方法。そして.. DirHandleのディレクトリ?
use DirHandle;
if (defined $d) {
while (defined($_ = $d->read)) { print "$_ \n" ; }
undef $d;
}
スキップする方法。そして.. DirHandleのディレクトリ?
use DirHandle;
if (defined $d) {
while (defined($_ = $d->read)) { print "$_ \n" ; }
undef $d;
}
ちなみに、使用しないでくださいundef $d
—$d = undef
が望ましいです。
いくつかの方法があります — Perl や正規表現を知っていれば、どれも簡単です
明らかなこと
while ( defined(my $node = $d->read) ) {
next if $node eq '.' or $node eq '..';
print "$dir\n";
}
正規表現の使用
while ( defined(my $node = $d->read) ) {
next if $node =~ /\A\.\.?\z/;
print "$dir\n";
}
...
または、Linuxディレクトリノードにはなどのような名前を付けることができるため、より整頓されていますが安全性は低くなり....
ます。ノードにドット以外のものが含まれていることを確認できます.
while ( defined(my $node = $d->read) ) {
next unless $node =~ /[^.]/;
print "$dir\n";
}