On Jan 29, Gary Stainburn said: >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.
It's not an error message, it's a warning. And it tells you what to do. > 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; >Value of <HANDLE> construct can be "0"; test with defined() at If you turn on 'use diagnostics', it will explain more about this warning. Suffice to say, reading from a filehandle can return JUST the string '0', which is technically false, and this will stop your while loop. If you don't want that to happen, you wrap the assignment in defined(): while (defined(my $line = <DAT>) and not $found) { ... } But I'd suggest rewriting your code thus: while (<DAT>) { print "line=$_" if $DEBUG > 0; $found = 1, last if /$localpart:/; } Here, we exit the loop immediately when $found is set. This lets us use a simply while clause (<DAT>) which assigns to $_ and tests for defined-ness implicitly. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>