On Thursday 15 April 2004 20:38, Randy W. Sims wrote: > > On 4/15/2004 11:24 PM, John W. Krahn wrote: > > > > On Thursday 15 April 2004 11:41, John W. Krahn wrote: > >> > >>On Thursday 15 April 2004 11:22, Jayakumar Rajagopal wrote: > >>> > >>>$a=100; $b=200; > >>>($a=3 && $b=6 ) if ( 1 == 1 ); > >>>print " $a $b \n"; > >>> > >>>Output : 6 6 > >>> > >>>OR my syntax is wrong ? > >> > >>You have a precedence problem. Your expression evaluates as: > >> > >>$ perl -MO=Deparse,-p -e'($a=3 && $b=6 ) if ( 1 == 1 );' > >> > >>($a = ($b = 6)); > >> > >>-e syntax OK > >> > >>You need to either add parentheses or use the lower precedence > >> 'and' operator: > >> > >>( ($a = 3) && ($b = 6) ) if ( 1 == 1 ); > >> > >>Or: > >> > >>( $a = 3 and $b = 6 ) if ( 1 == 1 ); > > > > Or you could use the comma operator: > > > > ( $a = 3, $b = 6 ) if ( 1 == 1 ); > > I'm as guilty as any at trying to write "clever" code like above, but > it really doesn't pay off in the long run. It's much easier to read > and less ambiguous to spell it out the old fashioned way: > > if (1 == 1) { > $a = 3; > $b = 6; > } > > I realize the examples above are contrived, but the point is still > valid: try to avoid too much clever code. I still have trouble > avoiding that temptation; perl makes it so easy.
You can do it that way with the statement modifier as well :-) do { $a = 3; $b = 6 } if ( 1 == 1 ); John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>