in reply to "if" and compound statement

The postfix form of if is a statement modifier, not a block modifier. And unadorned curlies form a block.

You could do either:

print( "one\n"), print( "two\n" ) if (1);

Or:

do{ print "one\n"; print "two\n"; } if (1);

Though there is little advantage of the latter over:

if( 1 ){ print "one\n"; print "two\n"; }

But most people will generally dislike it if you do either.

As an aside, your example is not a good one, as two print statements can always be combined:

print "one\ntwo\n" if (1);

Personally, I find that there are cases for which compounding statements with a postfix if makes sense. Eg:

while( my $input = <> ) { warn( "Bad input" ), next unless $input =~ m[...]; ... }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: "if" and compound statement
by juliosergio (Sexton) on Feb 13, 2012 at 16:48 UTC

    Thanks! I really appreciate your comments..
    -Sergio.

Re^2: "if" and compound statement
by JavaFan (Canon) on Feb 13, 2012 at 17:10 UTC
    As an aside, your example is not a good one, as two print statements can always be combined
    If you're going to nitpick about examples, I'm going to nitpick about your use of always. If the default filehandle is tied, if autodie is enabled, or if strings are overloaded, combining the given statements can lead the different results.

      Consider me duly chastened. Even though I only added the aside in an attempt to avoid the nitpickers :)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?