for my $next (@ARGV) {
opendir(PWD, "$next") and do {
my @files = readdir(PWD) or die "$next: $!";
closedir(PWD);
print join("\n", @files), "\n";
}
}
TIMTOWDI. I personally find this a little clearer, and is no less idiomatic:
foreach my $next (@ARGV) {
if (opendir(PWD, "$next")) {
my @files = readdir(PWD) or die "$next: $!";
closedir(PWD);
print join("\n", @files), "\n";
}
}
While using
and and
do like that is only slightly less clear than using a true 'if' block, it is slightly less clear than using a true 'if' block. :)