in reply to Can't happen bug follow-up -- Can an if/else be bypassed?

The following prints “not reached”:
$_ = <<'}'; if ($some_condition) { return $X; } else { return $Y; } die "not reached";

Replies are listed 'Best First'.
Re^2: Can't happen bug follow-up -- Can an if/else be bypassed?
by ursus (Acolyte) on Jul 05, 2008 at 20:32 UTC
    True, but that's not bypassing an if/else. Rather, it's creating a string that happens to contain the words 'if' and 'else'.
      $_ = <<'}';

      Eh? That's the left shift operator, right? How does that code work?

      from perlop:

      'Binary "<<" returns the value of its left argument shifted left by the number of bits specified by the right argument. Arguments should be integers.'
      but how does it let you fiddle with the if..else statement? (I'm not very good at 'non-obvious' code..)


      thanks! why_bird

      ........
      Those are my principles. If you don't like them I have others.
      -- Groucho Marx
      .......

        In this case, the << marks a here-doc, and '}' is the marker. This is equivalent:

        $_ = <<'END_OF_STRING'; if ($some_condition) { return $X; } else { return $Y; END_OF_STRING die "not reached";

        You can find here-docs documented in perlop.