in reply to Data Structures design help to represent function args for testing

I don't think you're going to get anywhere without using useful arguments for each function. I.e. just use perl:
my %functions = ( function1 => [ "arg1", { arg2 => val2 }], function2 => [ ... ], .... ); while (my ($func,$args) = each %functions) { no strict 'refs'; &{"harcommon::$func"}(@$args); }
or something similar.

updated s/wile/while/. thanks to FunkyMonk

  • Comment on Re: Data Structures design help to represent function args for testing
  • Download Code

Replies are listed 'Best First'.
Re^2: Data Structures design help to represent function args for testing
by goibhniu (Hermit) on Sep 21, 2007 at 00:50 UTC

    Wonderful - that's the kind of data structure I was looking for. Each arg list as an array. Each @funclist as the key to a hash pointing to the arg list.

    Any suggestions for a good data structure if I want more than one test list of args per function? (not a requirement in the original post - I'm just exploring the design space).


    I humbly seek wisdom.

      You're taking it up one level, so extrapolate the argument solution up one level - use a hash of arrays or an array of arrays:

      my %functions = ( function1 => {arglist1 => ["arg1", { arg2 => val2 }], arglist2 => [...], ... }, function2 => {...}, ..., ); while (my ($func, $argsList) = each %functions) { for my $key (keys %$argsList) { print "Test $func against args $key\n" &{"harcommon::$func"}(@{$argsList->{$key}}); } }

      or:

      my %functions = ( function1 => [["arg1", { arg2 => val2 }], [...], ... ], function2 => [...], ..., ); while (my ($func, $argsList) = each %functions) { for my $args (@$argsList) { print "Test $func against args $key\n" &{"harcommon::$func"}(@$args); } }

      Perl is environmentally friendly - it saves trees