[Israel.pm] why did it happen

Ephraim Dan E.Dan at F5.com
Wed Jun 20 10:11:23 PDT 2007


Operator precedence.

?: comes before =, so it's equivalent to:
my $a= ( (27>20)?$a="big":$a) ="small";
so "small" wins

thanks for the fun quiz.

Oh, and I think you mean "colleague"


-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Yossi Itzkovich
Sent: Wednesday, June 20, 2007 20:03
To: Perl in Israel
Subject: [Israel.pm] why did it happen

Hi,

A college here wanted to write this code:
my $a=(27>20)?"big":"small";

And instead wrote:
my $a= (27>20)?$a="big":$a="small");

Surprisingly $a was set to "small".  Why ?

Yossi

_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl




More information about the Perl mailing list