in reply to Complex conditional statements

I think that's difficult to understand, even in English.

I would definitely recommend
if !B then A else if (E and F) then (C and D)
Makes more sense to me <shrug>

On another note, I did try to make that work in a single statement and couldn't... but that doesn't prove anything.

Replies are listed 'Best First'.
Re^2: Complex conditional statements
by bofh_of_oz (Hermit) on Jun 16, 2005 at 14:24 UTC
    I think that's difficult to understand, even in English.

    Guess it's my Russian background and non-linear thinking then. ;)

    As for the

    if !B then A else if (E and F) then (C and D)
    AFAIK there is no then keyword in Perl, and I wanted to use the corerct syntax (i.e. to be able to replace A, B, C etc by valid statements to get a working code)

    By the way, where can I find references to the syntax of those Perl keywords? I tried to search for them, but they aren't functions, and Google promptly omits them from the search criteria...

    --------------------------------
    An idea is not responsible for the people who believe in it...

      oh, well, then you're still missing curly braces and mandatory parens :) I was equating to English. But I really meant "spoken language" when I said English... but perhaps that is more of a characterstic of the way English is constructed? I know for me, I had to re-read your original statement a few times to fully grok the meaning. It seems more natural as two separate concepts (personally speaking).

      Code-wise you want something like (if A, B, C and D were variables):
      if ( !$b ) { $a; } elsif ( $e and $f ) { $c and $d; }
      if they are statements, something similar should suffice, with perhaps more parens and/or do {} blocks. HTH
      By the way, where can I find references to the syntax of those Perl keywords? I tried to search for them, but they aren't functions, and Google promptly omits them from the search criteria...

      `perldoc perlop`

      Replace then with &&.

      IE if ( A ) { B } is the same as A && B. Likewise if ( !A ) { B } is the same as A || B.

      So to code if !B then A else if (E and F) then (C and D) you would say

      ( ! B ) ? A : ( ( E && F ) && ( C && D ) )

Re: Complex conditional statements
by hash (Scribe) on Jun 16, 2005 at 17:15 UTC
    It is possible, take a look at this piece of code:
    $status != $sigsegv or $ret = $counter + 4 and printf("> Done!\n$bugfi +le is vulnerable at $counter bytes!\n") and last;
    As you can see i have mixed "or","and", and could include some "if" statement just for example:
    $status != $sigsegv or $ret = $counter + 4 and printf("> Done!\n$bugfi +le is vulnerable at $counter bytes!\n") and last if $test eq 1;
Re^2: Complex conditional statements
by wolfger (Deacon) on Jun 20, 2005 at 16:02 UTC
    A unless B or (C and D) if (E and F)
    and
    I think that's difficult to understand, even in English. I would definitely recommend if !B then A else if (E and F) then (C and D)

    Demonstably difficult to understand, because I read it more like:

    if (E && F) { unless (B || (C && D)) { A } }