diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 47958b285174..b69113123098 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -6333,6 +6333,8 @@ value, not for its regular truth value. while (readdir $dh) { print "$some_dir/$_\n"; } + die "Got error while reading '$some_dir': $!" + if $!; closedir $dh; To avoid confusing would-be users of your code who are running earlier @@ -6342,6 +6344,8 @@ recent vintage: use 5.012; # so readdir assigns to $_ in a lone while test +In the case of an error, C will be returned and $! will be non-zero. + =item readline EXPR =item readline diff --git a/pp_sys.c b/pp_sys.c index 7d0af1f43e5c..2422b766d14c 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -4027,6 +4027,7 @@ PP(pp_readdir) } do { + SETERRNO(0,0); dp = (Direntry_t *)PerlDir_read(IoDIRP(io)); if (!dp) break;