This is ok:
if ($some_var==$some_value) {}
This is ok too:
print "hello" if ($some_var==$some_value);
But this raises an error:
if ($some_var==$some_value) print "some_message";
Why must 'if' clause in Perl come with either curly brackets or nothing?
To avoid the well-known problem in compiler construction known as a "dangling else". See http://en.wikipedia.org/wiki/Dangling_else
Perl has a rather complex syntax and is rather difficult to parse. I gather that curly brackets were made mandatory following an if clause so as to remove an ambiguity and make Perl code easier to parse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With