S02 says "A bare closure also interpolates in double-quotish context."

I presume that there are no restrictions on the code inside that closure, but all the examples I've seen have nothing but expressions inside the closure (though some examples, admittedly, do invoke subs and/or methods).

Question 1: Does

    my $s = ''
    say "Fire in the hole!{
        for reverse 1 .. 3 { $s = qq[$s $_]; }
      } BOOM!";

work? I.e., does it say this?

    Fire in the hole! 3 2 1 BOOM!

I'm not arguing that embedding that much code in a string is good style. I'm just asking if it's forbidden.

Question 2: Does C<for> return the value of its last statement? In other words, does this have the same effect as the previous example?

    my $s = '';
    say "Fire in the hole!{for reverse 1..3 { $s = qq[$s $_] }} BOOM!";

Question 3: Do quotes inside a closure inside a string get parsed exactly as if they were in code, or do they screw up the scanning of the outermost string? If the closure contains "real" code, then I should be able to replace qq[$s $_] with "$s $_" in the example. Does this work?

    my $s = '';
    say "Fire in the hole!{for reverse 1..3 { $s = "$s $_" }} BOOM!";
    # does this quote end the scan of string? -----^

Reply via email to