Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Complex conditional statements

by bofh_of_oz (Hermit)
on Jun 16, 2005 at 14:24 UTC ( [id://467285]=note: print w/replies, xml ) Need Help??


in reply to Re: Complex conditional statements
in thread Complex conditional statements

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

Replies are listed 'Best First'.
Re^3: Complex conditional statements
by Transient (Hermit) on Jun 16, 2005 at 14:30 UTC
    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
Re^3: Complex conditional statements
by xtype (Deacon) on Jun 16, 2005 at 17:31 UTC
    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`

Re^3: Complex conditional statements
by monarch (Priest) on Jun 17, 2005 at 07:42 UTC
    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 ) )

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://467285]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found