http://qs1969.pair.com?node_id=776347

merlinX has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, Can someone explain why the first ternary statement produces something completely different? The two ternary statements should be quivalent to the if else block that follows ... or not? I would expect this output:
rc_OK (=1) rc_OK (=1) ==== rc_OK (=1)
But instead I get this output:
check_group GRP_ADL001 0 rc_OK (=1) ==== rc_OK (=1)
code snippet
use strict; use Data::Dumper; my $checked; my $GroupDN="GRP_ADL001"; $checked->{Group}{$GroupDN}=1; #print Dumper($checked); my $rc_OK; exists($checked->{Group}{$GroupDN}) ? $rc_OK=1 : $rc_OK=check_group($G +roupDN,0); # this does NOT work $rc_OK=exists($checked->{Group}{$GroupDN}) ? 1 : check_group($GroupDN, +0); # this does work print "rc_OK (=$rc_OK)\n"; print "====\n"; if(exists($checked->{Group}{$GroupDN})){ $rc_OK=1 } else{ $rc_OK=check_group($GroupDN,0); } print "rc_OK (=$rc_OK)\n"; sub check_group{ my($group,$rc)=@_; print "check_group $group $rc\n"; return($rc); }