Larry Wall 提到:
Yes, unless we decide we need something like that for list
comprehensions. Maybe looping modifiers allow placeholders in what
would otherwise be an error...
Sure. How about this:
"
Use of a placeholder parameter in statement-level blocks triggers a
syntax error, because the parameter is not out front where it can be
seen. However, it's not an error when prefixed by a C<do>, or when
followed by a statement modifier:
# Syntax error: statement-level placeholder block
{ say $^x };
# Not an syntax error, though $x doesn't get the argument it wants
do { say $^x };
# Not an error at all
{ say $^x } for 1..10;
"
I do find it interesting that, because "any block just inside a left
parenthesis is immediately called like a bare block", we have:
my $x = {1+1}; # $x is a Code
my $y = ({1+1}); # $y is 2!
Is that correct?
Cheers,
Audrey