in reply to Testing for readdir failure

I inserted

use warnings; no warnings 'uninitialized';

into my code. (I included the no warnings because setting a variable to undef and then referring to that variable produces an uninitialized error, though what it clearly means is undefined, not uninitialized.)

This week's run failed in the old way, and there were no warnings issued.

I did NOT test the value of $! after the readdir because readdir does not set its value, as shown by this small piece of code executed under the debugger:

DB<9> p opendir(D,'.') 1 DB<10> p $!+0 2 DB<11> $! = 147 DB<12> p $!+0 147 DB<13> @d = readdir(D) DB<14> p $!+0 147 DB<15>

Replies are listed 'Best First'.
Re^2: Testing for readdir failure
by Anonymous Monk on May 25, 2013 at 00:42 UTC

    ???

    I did NOT test the value of $! after the readdir because readdir does not set its value, as shown by this small piece of code executed under the debugger:

    Here is a better one

    opendir D, q/./; closedir D; readdir D or die int $!, q/ /, $!; __END__ 9 Bad file descriptor at - line 3.

    perlvar#%!

    readdir STDOUT or die Fudge(); sub Fudge { join "\n", join(' ', int $!, $! ), join(' ', int $^E, $^E ), ( grep { $!{$_} } keys %! ), ' '; } __END__ 9 Bad file descriptor 6 The handle is invalid EVENT_SYSTEM_CAPTUREEND ERROR_INVALID_BLOCK EBADF EMR_SETWINDOWEXTEX EDGE_BUMP EMARCH_ENC_I17_IMM9D_SIZE_X at - line 1.
Re^2: Testing for readdir failure (debugger)
by LanX (Saint) on May 25, 2013 at 01:25 UTC
    You shouldn't do such tests in different lines of the debugger but in one line.

    DB<137> $!=undef; readdir $x or print 0+$!," ",$! 9 Bad file descriptor

    a) Each line is evaled in a different context!

    b) The debugger saves and restores special variables between evals, cause otherwise evaled code would change the error-state of the debugged program.

    Thanks BTW for discovering this!

    It shows fundamental differences between debugger and REPL functionality!

    UPDATE

    seems that I was wrong, the debugger can handle ERRNO in different lines, it's '$!=undef' which does the difference!

    DB<100> opendir $x,'.';closedir $x; DB<101> readdir $x DB<102> print 0+$!," ",$! 29 Illegal seek DB<103> $!=undef DB<104> readdir $x DB<105> print 0+$!," ",$! 9 Bad file descriptor

    For more details see Re: Testing for readdir failure (Perl-bug)

    Cheers Rolf

    ( addicted to the Perl Programming Language)