Re: perl flawed or my fault



Thank you everyone, I see the mistake already.

John W. Krahn wrote:
paul wrote:

please help me the check the following code

use strict;

my $something = 'phal';
my $otherthing = 'paul';

my $note_whom = 'szmuzu\'mi';

defined($something) ? $note_whom = $something : $otherthing =
'singapore';

print "$note_whom \n $otherthing \n";

The result is: singapore
singapore

I don't know why the scalar $note_whom get the value that is assigned
to $otherthing.

Please give me the explaination, and thank you.

Because of precedence you have:

(defined($something) ? $note_whom = $something : $otherthing) = 'singapore';

You need to add parentheses:

defined($something) ? ($note_whom = $something) : ($otherthing = 'singapore');



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall

.



Relevant Pages

  • Re: perl flawed or my fault
    ... use strict; ... my $otherthing = 'paul'; ... The result is: singapore ... sort them into the correct order. ...
    (comp.lang.perl.misc)
  • Re: perl flawed or my fault
    ... paul wrote: ... The result is: singapore ... to $otherthing. ... use strict 'refs'; ...
    (comp.lang.perl.misc)
  • Re: perl flawed or my fault
    ... paul wrote: ... use strict; ... The result is: singapore ... to $otherthing. ...
    (comp.lang.perl.misc)
  • perl flawed or my fault
    ... use strict; ... The result is: singapore ... to $otherthing. ... Please give me the explaination, ...
    (comp.lang.perl.misc)