Perl – Nested ‘if’ or something else in Perl

if statementperl

I struck in a simple nested if statement.

The requirement is as below.

if (Condition1) {
    if (Condition2) {
        print "All OK";
    }
    else {
        print "Condition1 is true but condition2 not";
    }
    else {print "Condition1 not true";
}

Is it possible to write this code in Perl or is there another short or better way to fulfil this condition?

Best Answer

The if condition 1 is true. The clause is missing its closing } which should be inserted right before the last else.

Try to line things up this way:

if (...) {
    if (...) {
        ...
    }
    else {
        ...
    }
}
else {
    ....
}