$! is not guaranteed to be cleared if there was no error. This means you
probably don't have a "Bad file descriptor" error, it's just the last value
of $! (or 'errno'). See perlvar:
http://perldoc.perl.org/perlvar.html#Variables-related-to-filehandles

For example, let's try $! when I haven't run a thing before (using
Devel::REPL):

[anneli@asu ~]$ LANG=C re.pl

$ $!
No such file or directory
$

At some point in the past this error *may* have occurred, but certainly
nothing now.

This means your <HD> did probably work; only try using $! if you actually
get an error condition (e.g. if <HD> is undef).

Note that bare filehandles (HD) and two-argument open are discouraged
(deprecated?), though it doesn't matter so much for a one liner.

- Anneli

2011/11/5 Ken Peng <kenp...@freenet.de>

> Hi,
>
> $ perl -le 'open HD,"/etc/passwd" or die $!; <HD>; print $!'
> Bad file descriptor
>
> what does this error mean? why it happens?
>
> Thanks.
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to