Re: perl flawed or my fault
- From: "paul" <betterdie@xxxxxxxxx>
- Date: 2 Oct 2006 22:10:16 -0700
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
.
- References:
- perl flawed or my fault
- From: paul
- Re: perl flawed or my fault
- From: John W. Krahn
- perl flawed or my fault
- Prev by Date: Re: Modifying a one-liner
- Next by Date: FAQ 1.16 How can I convince others to use Perl?
- Previous by thread: Re: perl flawed or my fault
- Next by thread: FAQ 1.16 How can I convince others to use Perl?
- Index(es):
Relevant Pages
|