carcassonne has asked for the wisdom of the Perl Monks concerning the following question:
I'm used to call functions like this:
my %commands = ( command1 => { description => "Does something", function => sub { my $var = shift; print "var = $var\n"} }, ) my $cmd = 'command1'; $commands{$cmd}{function}($param)
So I thought it could be as easy to quickly change, for development purposes, a function under test by doing:
my $func = \&version1; is($func($param), 0, 'makes sense'); my $func = \&version2; is($func($param), 0, 'does it ?'); sub version1{[some code]} sub version2{[some code]}
But no dice. Syntax error.
So how are 'function pointers' used with scalars ?
Thanks !
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Quickly changing a function under test in Test::More
by duff (Parson) on Mar 09, 2006 at 13:30 UTC | |
|
Re: Quickly changing a function under test in Test::More
by fizbin (Chaplain) on Mar 09, 2006 at 14:52 UTC | |
|
Re: Quickly changing a function under test in Test::More
by gube (Parson) on Mar 09, 2006 at 14:18 UTC |