A. Pagaltzis writes:
> my $glob = do { no strict "refs"; \*$_ };
> *$glob = sub { ... };
>
> The temporary seems unavoidable; apparently Perl’s grammar rules (or
> even its semantics) are non-orthogonal here, in that it won’t permit
> this:
>
> *{ do { no strict "refs"; \*$_ } } = sub { ... };
In the perls I've tried, you first get a warning about "Ambiguous use of
*{do{...}} resolved to *do{...}"; that suggests trying this version,
which does work:
*{ (do { no strict "refs"; \*$_ }) } = sub { ... };
I personally find this clearer, even though it does require a temporary:
for my $name (...) {
my $code = sub { ... };
no strict qw<refs>;
*$name = $code;
}
Or even:
sub set_symbol {
my ($name, $value) = @_;
no strict qw<refs>;
*$name = $code;
}
for my $name (...) {
set_symbol($name, sub { ... });
}
--
Aaron Crane
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/