Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Testing for readdir failure

by Laurent_R (Parson)
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


Comment on Re^3: Testing for readdir failure
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029942]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2014-12-26 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls