develooper Front page | perl.beginners | Postings from January 2004

Re: error but code works

Thread Previous | Thread Next
From:
James Edward Gray II
Date:
January 29, 2004 06:30
Subject:
Re: error but code works
Message ID:
03E9B711-5267-11D8-AB15-000A95BA45F8@grayproductions.net
On Jan 29, 2004, at 8:07 AM, 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:/;
>       }
>

How about we simplify that loop a little:

while (<DAT>) {
	print "line=$_" if $DEBUG;
	last if /$localpart/;
}

That's a little easier on the eyes, I think.  It means the same and it 
will remove the error.

Hope that helps.

James

>       close DAT;
>
> root@stan 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...
> [root@stan input]#
> -- 
> Gary Stainburn
>
> This email does not contain private or confidential material as it
> may be snooped on by interested government parties for unknown
> and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
>
>
> -- 
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About