Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^3: Testing for readdir failure

by Laurent_R (Canon)
on Apr 22, 2013 at 17:53 UTC ( #1029942=note: print w/replies, xml ) Need Help??

in reply to Re^2: Testing for readdir failure
in thread Testing for readdir failure

When the readdir fails to deliver the entire contents of the directory, there is NO warning, nor any other message, issued by Perl. Thus, I don't believe that trapping warnings, nor the warnings pragma, will help.

It may be right, but if you don't try, you'll never know. Especially, if you don't turn on warnings with the warnings pragma, you're not gonna get those warnings. In my tests, when I tried to readdir on a close dir, I did not get any message unless I explicitly added the 'or die "$!"' clause to my readdir instruction.

Consider this:

$ perl -e  '@c=readdir DIR ; print "@c\n";'

No warning, nothing. Compare to this;

$ perl -w -e '@c=readdir DIR ; print "@c\n";' Name "main::DIR" used only once: possible typo at -e line 1. readdir() attempted on invalid dirhandle DIR at -e line 1.

Turning on the warnings with the -w command line option gave me two warnings that might explain where my problem is. Or consider this:

$ perl -e '@c=readdir DIR or print "$!"; print "@c\n";' Bad file descriptor

Replies are listed 'Best First'.
Re^4: Testing for readdir failure
by Bob Cook (Acolyte) on Apr 23, 2013 at 00:44 UTC

    Wow, I had no idea that warnings had different "levels" and that by default, some weren't issued. I don't think I want to enable ALL warnings, but the io bunch looks appropriate.

    Thanks for the suggestion.

      I think that pretty much everyone on this forum will agree that you should always "use strict;" and "use warnings;" for every single program that you write, except possibly for programs which have strictly less than two lines. This is increedibly useful to find syntax and programming errors.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029942]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2018-06-21 12:33 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.