From: Carl F. <fri...@ex...> - 2002-04-07 05:48:18
|
Jumping in again to prod others to action :-) I personally have a dislike for this style of "c" coding: > > if ($state =3D state_now $pedestal_light) {...} I believe (haven't the patience at this hour to check) that the -w option will emit a complaint about this.=20 In fact, this one is on my list of "why I hate C" (even though it's Perl). C/Perl syntax here is a bit vague, allowing a multiplicity of actions to occur: first, the replacement of the current lvalue of $state with the result of the state_now function; then, the testing of the result within the if (). I've caught this bug many times (in C) when the original coder had intended X =3D=3D (comparison) rather than X =3D (replacment). That's why the alternate coding style is clearer and safer (obviously, in my opinion): > > if (state $pedestal_light eq ON) print_log "the light is on\n"; Your instincts are right. You're getting it. Carl > -----Original Message----- > From: Bruce Winter [mailto:bruce%mis...@fw...] > Sent: Saturday, April 06, 2002 11:35 PM > To: Misterhouse-Users > Subject: [misterhouse-users] RE: Please correct me if I am incorrect >=20 >=20 > Your post is correct. I think you are indeed getting the=20 > hang of this! >=20 > If you wanted to find the current state of a light periodically, try > something like this: >=20 > if (new_minute 5 and state $pedestal_light eq ON) print_log=20 > "the light is > on\n"; ... |