in reply to how to get alias name of anonymous sub?
As noone seem to have pointed already, there's one important module on that subject which is Sub::Name. It should allow you to:
use Sub::Name foreach (keys %news_sites) { *{$_} = subname "generator_for_$_" => sub {...} }
But note that you seem to be missing one more important concept here, which is the concept of closures
foreach my $key (keys %news_sites) { *{$key} = sub { ... # as the $key variable was declared in the outer scope of the s +ubroutine, # if the code reference survives longer than this scope it will + retain its # value warn $key; # this will warn the value used when defining this s +ub. } }
daniel
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: how to get alias name of anonymous sub?
by gian (Novice) on Nov 29, 2010 at 16:49 UTC | |
by kcott (Archbishop) on Nov 29, 2010 at 17:48 UTC |
In Section
Seekers of Perl Wisdom