In Perl, inconsistent rules on using parenthesis.
When you print
, you can use parenthesis or not:
print("Hello, world!\n");
print "Hello, world!\n";
But if you print to a filehandle, you can't use them:
print FILE "Hello, world!\n";
(This also brings up the awkward syntax for printing to files - look, Ma, no comma! - but that's not what this post is about.)
However, flow control statements must have parenthesis:
while(1) {
...unless you use postfix notation:
dosomething() while(1);
dosomething() while 1;
Personally, I'm a fan of dropping the parenthesis altogether, except when you need them to resolve ambiguities (which is what parenthesis are for) and typing:
while 1 {
Because we all know that anything after the while
and before the {
is the condition.