Re: perl flawed or my fault



"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
.



Relevant Pages

  • Re: <ctype.h> toLower()
    ... provided we don't try to recommend that other people use our ... If someone posts a question with code that assumes ASCII ... version of a standard library function (even if you replicate _all_ ... the functionality) as anything other than a learning exercise is not ...
    (alt.comp.lang.learn.c-cpp)
  • Re: If you were inventing CoBOL...
    ... "Robert Wagner" wrote in message ... > statements use parentheses on statements containing more than one ... The 2002 standard points out some of the problems with Abbreviated Combined ... Relation Conditions in an ISO NOTE on page 137 relating to the use of NOT ...
    (comp.lang.cobol)
  • Re: macros and side effects
    ... and I assume standard macros are "clean"... ... Perhaps because of the Standard? ... Provided that a library function can be declared without reference to ... fully protected by parentheses where necessary " ...
    (comp.lang.c)
  • Re: f. to string?
    ... Is there a general concept for redirecting the output to ... Additional problem: FICL doesn't have REPRESENT. ... Assuming you have a "standard" REPRESENT then ... this is an "old" version, which I only recommend for systems ...
    (comp.lang.forth)
  • Re: () in output lists
    ... and I got numerous errors about statements like this: ... extension of the standard. ... If I remove the parentheses ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)