in reply to Invoking a string reference to a anonymous subroutine
out:use warnings; use strict; my $_parse_element_configuration = sub{ print "element_configuration: @_\n" }; my $handler = "_parse_element_configuration"; my $self=42; #--- dispatch table my %parser; $parser{_parse_element_configuration}=$_parse_element_configuration; my $meth=$parser{$handler}; $self->$meth(666); #--- lex sym ref via eval $meth= eval "\$$handler"; $self->$meth(777); #--- abstracted sub handle { my $name=shift; return eval "\$$name"; } handle($handler)->($self,888);
element_configuration: 42 666 element_configuration: 42 777 element_configuration: 42 888
Cheers Rolf
( addicted to the Perl Programming Language)
corrected c&p problem but created duplicate! :-(
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Invoking a string reference to a anonymous subroutine
by AnomalousMonk (Archbishop) on Jan 14, 2014 at 22:43 UTC | |
by LanX (Saint) on Jan 14, 2014 at 22:53 UTC | |
by AnomalousMonk (Archbishop) on Jan 15, 2014 at 00:04 UTC | |
|
Re^2: Invoking a string reference to a anonymous subroutine
by Superfox il Volpone (Sexton) on Jan 15, 2014 at 11:15 UTC | |
by LanX (Saint) on Jan 15, 2014 at 11:24 UTC | |
by Superfox il Volpone (Sexton) on Jan 15, 2014 at 12:48 UTC | |
by LanX (Saint) on Jan 15, 2014 at 13:26 UTC |