in reply to Re^3: Curly braces variable
in thread Curly braces variable
They're both basically the same construct...
How do you figure? One of them is a literal identifier and the other is an expression.
... but the syntax on line #2 is a symbolic reference...
Yes, because it's not a literal identifier. Compare:
my ${ hello_world } = "hello world";... to:
my ${ $_ = hello_world } = "hello world";Perl complains about the latter because you can't use a scalar dereference as the name of a lexical variable in a declaration. (You don't get to use symbolic references with lexicals anyway, at least without XS.) A quick of the grammar allows you to use a block immediately following the scalar sigil, but you get the runtime error in the my op if you have anything other than a literal scalar name here.
|
|---|