![]() |
Nested if statement inside a while loop.
Can some perl god, please highlight the error of my ways?
For some reason the print statement below always returns true, assuming the first check is valid. while (<FILE>){ if (/$check/){ my @DETAIL = split(/,/,$_); my @OTHERDETAIL = split(/:/,$DETAIL[2]); if ($DHCPDETAIL[3]=="somevalue"){ print "You should only see me after above if statement evaluated"; } } It's driving me crazy. Many, many thanks. |
Re: Nested if statement inside a while loop.
gstewart@gmail.com wrote:
> Can some perl god, please highlight the error of my ways? > > For some reason the print statement below always returns true, Unless you close the STDOUT filehandle then yes, print() will return 'true', but that is probably not your problem as you are not testing the return value from print(). > assuming the first check is valid. > > > while (<FILE>){ > if (/$check/){ > my @DETAIL = split(/,/,$_); > my @OTHERDETAIL = split(/:/,$DETAIL[2]); > if ($DHCPDETAIL[3]=="somevalue"){ You are using a numerical comparison on a string. Perhaps you meant: if ( $DHCPDETAIL[ 3 ] eq "somevalue" ) { > print "You should only see me after above if statement evaluated"; > } > } John -- use Perl; program fulfillment |
Re: Nested if statement inside a while loop.
Ok, I'm retarded. I see the error of my ways!
It should be: if ($DHCPDETAIL[3] eq "somevalue"){ etc... Sorry for the spam..... |
Re: Nested if statement inside a while loop.
Thanks John, you're right. It was a complete newbie mistake. My
apologies, it's late in the day and I'm tired!!!! :-) |
Re: Nested if statement inside a while loop.
Thanks John, you're right. It was a complete newbie mistake. My
apologies, it's late in the day and I'm tired!!!! :-) |
Re: Nested if statement inside a while loop.
gstewart@gmail.com <gstewart@gmail.com> wrote:
> Can some perl god, please highlight the error of my ways? A deity is hardly required, a _machine_ could have shown you the error, but you did not ask it to. > if ($DHCPDETAIL[3]=="somevalue"){ You should always enable warnings when developing Perl code! Argument "somevalue" isn't numeric in numeric eq (==) at ... > It's driving me crazy. Program without use warnings; use strict; and you can expect a good deal more mental anguish. -- Tad McClellan SGML consulting tadmc@augustmail.com Perl programming Fort Worth, Texas |
| All times are GMT. The time now is 10:46 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.