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

my $handler = \*{$name}{CODE};
instead - sorry for not testing my stuff out.

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
    Here's a more slim-line version
    sub call_service { croak "Couldn't find handler for $name" unless my $c = shift->can(shift); goto &$c; }
    HTH

    _________
    broquaint

Re^2: Passing a data structure via a dynamically-built subroutine call
by Tanalis (Curate) on Jun 21, 2004 at 09:34 UTC