Gary Stainburn wrote:
> Hi folks,
> 
> I've got the following code which works, but generates the error
> message following it.  I've tried varying the code to eliminate the
> error but I only manage to get either the working code with error or
> non-working code without error.
> 
> (Line 95 is the while line)
> 
>       print "checking file $fname...";
>       open DAT,"<$fname" ||die "cannot open $fname: $!\n";
>       my $found=0;
>       while ((my $line=<DAT>) && (! $found)) {
>       print "line=$line" if ($DEBUG > 0);
>         $found=1 if $line=~/$localpart:/;
>       }
>       close DAT;
> 
> [EMAIL PROTECTED] input]# tidy-mailq|gvim -
> Value of <HANDLE> construct can be "0"; test with defined() at
> /root/bin/tidy-mailq line 95.
> Vim: Reading from stdin...
> [EMAIL PROTECTED] input]#

>From perldoc perldiag:

  Value of %s can be ""0""; test with defined()
      (W misc) In a conditional expression, you used <HANDLE>, <*>
      (glob), "each()", or "readdir()" as a boolean value.  Each of these
      constructs can return a value of "0"; that would make the condi-
      tional expression false, which is probably not what you intended.
      When using these constructs in conditional expressions, test their
      values with the "defined" operator.

changing:
   while ((my $line=<DAT>) && (! $found)) {

to
   while (defined(my $line=<DAT>) && (! $found)) {

should make the warning go away.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to