Re: perl flawed or my fault
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Tue, 03 Oct 2006 03:44:34 GMT
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
.
- Follow-Ups:
- Re: perl flawed or my fault
- From: paul
- Re: perl flawed or my fault
- From: Eric Schwartz
- Re: perl flawed or my fault
- References:
- perl flawed or my fault
- From: paul
- perl flawed or my fault
- Prev by Date: Re: Text::CSV_XS Trying to find empty field
- Next by Date: Re: Modifying a one-liner
- Previous by thread: Re: perl flawed or my fault
- Next by thread: Re: perl flawed or my fault
- Index(es):
Relevant Pages
|