in reply to Passing a data structure via a dynamically-built subroutine call
Don't use eval but get a reference to the code you want to call, and call that like any other subroutine:
use Carp qw(croak); sub call_service { my $svc = shift; my $cmd = shift; my @args = @_; my $name = "$svc\::$cmd"; my $handler = *{$name}{CODE}; croak "Couldn't find a handler for $name" unless $handler; # maybe log the invocation to your logfile? return $handler->(@args); }
This code is untested, sorry - maybe you need to take a reference like
instead - sorry for not testing my stuff out.my $handler = \*{$name}{CODE};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing a data structure via a dynamically-built subroutine call
by broquaint (Abbot) on Jun 21, 2004 at 09:46 UTC | |
|
Re^2: Passing a data structure via a dynamically-built subroutine call
by Tanalis (Curate) on Jun 21, 2004 at 09:34 UTC |