in reply to and this or that

Your precedence problem goes away with a little untangling. Move the error handling for opendir() in closer to the call, rather than out past the readdir(). Here's I'd code it.
for my $next (@ARGV){ opendir(PWD, "$next") or die "$next: $!"; my @files = readdir(PWD) or die "$next: $!"; closedir(PWD); print join("\n", @files), "\n"; }
(Updated to add error handling after readdir(), too.)

Or, if you really want to use precedence, and if you want to ignore non-directories in @ARGV, consider

for my $next (@ARGV) { opendir(PWD, "$next") and do { my @files = readdir(PWD) or die "$next: $!"; closedir(PWD); print join("\n", @files), "\n"; } }

Replies are listed 'Best First'.
Re: Re: and this or that
by Fastolfe (Vicar) on Feb 06, 2001 at 01:01 UTC
    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. :)