Is it possible to include several statements in the statement modifier form of if?

perl

Solution

Simply add a `do` before it:

do {print "4";print="2";} if 4!=2;

Note that I wouldn't recommend this kind of code in any real-life scenario. The normal

if (condition)
{
    code;
}

form is much more familiar, easier to read and debug, and has indentation to guide the reader regarding the flow of control.

Problem

Teaching myself Perl with Project Euler. Anywho, ``` print "Hei" if 1==1; ``` works like a charm. Is it possible to include several statements before the if, like so ``` {print "4";print="2";} if 4!=2; ``` I'm aware that specific syntax does not work, but I think what I want to do is obvious. Possible or not? Ps. I'm also aware I could do this with a regular ``` if(){} ```

Original source