Hartmut Camphausen <> wrote:
> Hi all,
>
> Consider this snippet:
>
> open ($fh, '<', $fref) || die $!
> warn "(1) $!" if $!;
>
>
> It produces this output:
>
> (1) Bad file descriptor at E:\[Public]\cgi-bin\lib\Text\testmisc.pl
> line 10.
Open did not fail. Therefore, the value of $! is meaningless. Meaningless
can be anything, including the value you see above.
> Any idea, why open() generates an error ($! set) without failing?
Setting $! is *not* generating an error[1]. The way that open indicates an
error is by returning a false value (or conceivably by dying). It did not
do that.
[1] And "open" is not setting it anyways, at least not directly. Most
likely your use of open is triggering the loading of PerlIO::scalar, and it
is the loading of PerlIO::scalar that is setting $!, but in an innocuous
manner. On my system, if I preload that module by "use PerlIO::scalar",
and then reset $! to 0, then do your open, after the open $! remains 0.
But that doesn't really matter, as by inspecting $! when an error has not
occurred you are living in sin.
Xho
--
--------------------
http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.