> -----Original Message----- > From: news [mailto:[EMAIL PROTECTED] On Behalf Of Ingo Blechschmidt > Sent: Saturday, May 21, 2005 7:22 AM > To: perl6-language@perl.org > Subject: Declaration of my() variables using symbolic referentiation > > Hi, > > am I correct in the assumption that the following is an error? > # Not in a BEGIN block > my $::(calc_varname()) = 42; > > I think so, as my() is a compile-time operation, but in this > example, the variable name is not known until runtime, so I > think this should be forbidden. Correct? > > But: > BEGIN { > my $::(calc_varname()) = 42; > } > I think this one is ok, as the compiler can invoke > &calc_varname at compile-time, and therefore know the variable > name at compile-time. Correct? > > FWIW, I wouldn't mind BEGIN { my $::(...) } being disallowed, too > (consistency). >
Even if it's legal it's fairly useless because $::(calc_varname()) goes out of scope at the end of the BEGIN block. You could probably write a macro to accomplish what you want: macro declare_var(String $varName) {"\$$varName"} Then you wouldn't even need the BEGIN block. my declare_var(calc_varname()) = 42; The compiler wouldn't know the variable name until runtime, but I think this just means that this just transforms compile-time errors to runtime errors. Joe Gottman