You were very close:
$ cat sploot.pl #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use Test::More; my %sub = ( t01=>{ name=>\&mine, args=>[qw/one first two second/] }, ); $sub{t01}{name}(@{$sub{t01}{args}}); sub mine { my %args = @_; ok( $args{one} eq 'first', 'arg one' ); ok( $args{two} eq 'second', 'arg two' ); done_testing; } $ perl sploot.pl ok 1 - arg one ok 2 - arg two 1..2
The bit that hurt you was that you didn't tell perl to expand the arguments into a list. So your function just got an array ref, so you probably got the "odd number of elements for hash" error. I elided the '->' since they're not strictly necessary, but they don't hurt either. (I typed it in, rather than cut & paste for some odd reason...)
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: A dispatch table to match named params of a sub
by roboticus
in thread A dispatch table to match named params of a sub
by neilwatson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |