Re: Bug#214036: im: imput doesn't work with Perl 5.8.1
On Tue, Oct 21, 2003 at 01:13:49AM +0900, Tatsuya Kinoshita wrote:
>With the perl 5.8.1 package, the line input operator (<>) causes
>"Bad file descriptor". This problem is reproducible by the
>following sample code.
>
>----
>#!/usr/bin/perl
>$file = "/etc/debian_version";
>open(FH, $file) or die "Cannot open $file";
>$! = 0;
>$line = <FH>;
>if ($!) {
> print "System error: $!\n";
>}
>print "$line\n";
>close(FH);
>----
>
>Is this a bug in the perl 5.8.1 pakcage? Or a Perl's feature?
>What should I do?
The value of $! is not meaningful unless there was an error status
returned by a function/operator, which may involve a bunch of system
calls some of which quite validly fail.
For example:
$ perl -le 'open F, "/etc/passwd"; print $!'
Inappropriate ioctl for device
In your example above, you should test the return value of the <>
operator rather than $!, which you only need to check if the return
value was not defined:
unless (defined ($line = <FH>)) {
print "System error: $!\n";
}
--bod
Reply to: