Re: perl flawed or my fault
- From: Eric Schwartz <emschwar@xxxxxxxxx>
- Date: 02 Oct 2006 22:12:32 -0600
"John W. Krahn" <someone@xxxxxxxxxxx> writes:
Because of precedence you have:
(defined($something) ? $note_whom = $something : $otherthing) = 'singapore';
You need to add parentheses:
defined($something) ? ($note_whom = $something) : ($otherthing = 'singapore');
Or better yet, write it out:
if (defined($something)) {
$note_whome = $something;
} else {
$otherthing = 'singapore';
}
I always recommend against the ?: operator unless it's for something
small and self-contained. I avoid using it except for rvalues, unless
not using it will make things unacceptably ugly. Yes, this is a vague
standard. Here' an exampe of what is acceptable:
my $foo = $bar ? 0 : 1;
Here's something that isn't:
($var == 'foo' and $bar < 6 or $x > $y) ? ($this = something($else, 'maybe') or die "um, I dunno") : call_cows($potatoes);
-=Eric
.
- Follow-Ups:
- Re: perl flawed or my fault
- From: John W. Krahn
- Re: perl flawed or my fault
- From: anno4000
- Re: perl flawed or my fault
- 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: 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
|