develooper Front page | perl.perl5.porters | Postings from February 2004

Re: [perl #24194] Bad file descriptor, Error after upgrade from 5.8.0 to 5.8.1

Thread Previous
Dave Mitchell
February 26, 2004 07:44
Re: [perl #24194] Bad file descriptor, Error after upgrade from 5.8.0 to 5.8.1
Message ID:
On Sun, Oct 12, 2003 at 11:06:49PM -0000, (via RT) wrote:
> This is a bug report for perl from,
> generated with the help of perlbug 1.34 running under perl v5.8.1.
> <CODE>
> print 'Called from '. (join ' : ', caller ). ' at line '. __LINE__." \$!: $!.\n";
> my $schack = <RSnaps>;
> chomp $schack;
> print "In Snaps1:\$!: $!. gameStatus: $gameStatus, Schack: $schack\n";
> <\CODE>
> Called from Net::Telnet : /usr/local/lib/perl5/site_perl/5.8.1/Net/ : 2123 at line 103 $!: Interrupted system call.
> In Snaps1:$!: Bad file descriptor. gameStatus: 3, Schack: oGame over
> The code is called from a caught $SIG{USR1} not realy from but the
> script is usually waiting in a Telnet::getline() when the signal arrives.
> This did not happen in 5.8.0 but it does with 5.8.1.

Sorry for the late reply to this bug report.

I believe you are slightly misunderstand how $! should be used.
$! refers to the error status from the last OS system call that *failed*.
If a later call succeeds, $! still holds to the old error message, eg:

    print "err1: $!\n";
    open F, "/nosuchfile"; print "err2: $!\n";
    open F, "/etc/passwd"; print "err3: $!\n";

    err2: No such file or directory
    err3: No such file or directory

You should only examine the content of $! when you know an error has
occured; usually by the perl function returning undef, eg

    open F, "/nosuchfile" or print "err: $!\n";

A single perl function such as 'open' can sometimes make several OS
system calls, not all which may succeed, but for which the overall result
is regarded as being successul; eg 'use Foo' may fail to open several
files before finding the file in @INC.

Hope this helps,


A major Starfleet emergency breaks out near the Enterprise, but
fortunately some other ships in the area are able to deal with it to
everyone's satisfaction.
    -- Things That Never Happen in "Star Trek" #13

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About