in reply to If Statement

  1. By rule #1 {grin}. "Larry said so."
  2. There's never a chance of the "dangling else" problem.
  3. The syntax would be ambiguous without it. I forget the exact case, but apparently it'd be hard to tell for certain Perl constructs whether it was a curly-expression or the block that belongs to the if, and then you wouldn't know where the end of the block was.
  4. Perl has the "backward if" that C doesn't have:
    $simple_expression if $some_condition;

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: If Statement
by jdporter (Paladin) on Nov 05, 2002 at 17:46 UTC
    3. # The syntax would be ambiguous without it. I forget the exact case,...

    It's like this:

    if ( $foo ) if ( $bar ) quux(); else # ???
    Which if is that else supposed to go with?
      No, not the dangling-else problem. I already addressed that in "point 2".

      There's something that's in Perl that's not in C that would have made it hard to tell if there was a single expression or a block following. Maybe it's just the anonymous hash constructor, but back when braces were made mandatory, there was no anon-hash constructor, so I don't think that was it.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

Re^2: If Statement
by Aristotle (Chancellor) on Nov 06, 2002 at 12:17 UTC
    Re: point 3: Maybe that C doesn't have naked blocks? So would if($cond) { $foo } $bar; mean
    if($cond) { $foo } $bar;
    or is it
    if($cond) { { $foo; } $bar; }

    Makeshifts last the longest.

        Oh wow. I had no idea - never seen one in a C source.

        Makeshifts last the longest.