http://qs1969.pair.com?node_id=477651


in reply to What is this doing, and why is this a good method of doing it?

It is producing a named subroutine for each name in @x. Even if somefunction() returns names which would be illegal for a sub, a function of the name will be provided.

use strict; use warnings; sub somefunction { qw/foo bar 123/ } my @x = somefunction(); for (@x) { my $foo = "${_}_func"; *{;no strict 'refs'; \*$_} = sub { $foo }; } print &123(),$/; # omitting the & sigil gives syntax error __END__ 123_func

The tight scope of no strict 'refs'; is remarkable. I've never seen it done that way. I think it is the primary advantage of doing this: stricture in in force in the sub definition. The construction seems to be equivalent to,

*{ +do { no strict 'refs'; \*$_ } } = sub { # . . . };

After Compline,
Zaxo