Ask a Question related to PERL Beginners, Design and Development.
-
Gary Stainburn #1
error but code works
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;
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
Gary Stainburn Guest
-
ASP code works everywhere except Mac OS9 IE
I have an ASP page that loads fine on all browsers and platforms that I've checked except for IE5 on a MacOS9.... -
code no longer works from ColdFusion 5
Any Idea why this code works in ColdFusion 5 and not in ColdFusion MX <CFQUERY NAME="WaasSUMQuery" DATASOURCE="WAASAccount"> SELECT *... -
Code no longer works
I have a machine that I was using as a web server that I recently changed the operating system from Windows 2000 Professional to Windows Advanced... -
Check this code. Works in 5, not in 6!!
Hi. I'm trying to get the .focus to change from textfield to the next by pressing the TAB key. This code works in a Flash 5 movie, but not a 6. The... -
Code works well in A97 and Xp, but bombs in A2000.
Here is a procedure which produces a duplicate record in an order entry program, along with subform data. It has worked well for years in A97 and I... -
Bob Showalter #2
RE: error but code works
Gary Stainburn wrote:
From perldoc perldiag:> 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;
>
> 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]#
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.
Bob Showalter Guest
-
James Edward Gray II #3
Re: error but code works
On Jan 29, 2004, at 8:07 AM, Gary Stainburn wrote:
How about we simplify that loop a little:> 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:/;
> }
>
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: [email]beginners-unsubscribe@perl.org[/email]
> For additional commands, e-mail: [email]beginners-help@perl.org[/email]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>James Edward Gray II Guest
-
Jeff 'Japhy' Pinyan #4
Re: error but code works
On Jan 29, Gary Stainburn said:
It's not an error message, it's a warning. And it tells you what to do.>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.
> 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;If you turn on 'use diagnostics', it will explain more about this warning.>Value of <HANDLE> construct can be "0"; test with defined() at
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]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<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. ]
Jeff 'Japhy' Pinyan Guest
-
Gary Stainburn #5
Re: error but code works
On Thursday 29 Jan 2004 2:25 pm, James Edward Gray II wrote:
Hi James,> 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/;
> }
my problem was having the result in $found after the loop ended, I've amended
your code so that I have
if (/$localpart:/) { $found=1; last;}
Thanks for the help.
Gary
-->
> 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: [email]beginners-unsubscribe@perl.org[/email]
> > For additional commands, e-mail: [email]beginners-help@perl.org[/email]
> > <http://learn.perl.org/> <http://learn.perl.org/first-response>
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
Gary Stainburn Guest



Reply With Quote

