Say I have a class with a private dispatch table.
$this->dispatch = array(
1 => $this->someFunction,
2 => $this->anotherFunction
);
If I then call
$this->dispatch[1]();
I get an error that the method is not a string. When I make it a string like this:
$this->dispatch = array(
1 => '$this->someFunction'
);
This pro...
A dispatch table is a data structure that associates an index value to an action. It's a rather elegant replacement for a switch-type statement. Most languages have support for dispatch tables, but the support ranges from do-it-yourself to built-in and hidden under a layer of syntax. How does your favorite language implement dispatch ...
I'd like to be able to store a function in a hashtable. I can create a map like:
hash = {}
hash["one"] = def():
print "one got called"
But I'm not able to call it:
func = hash["one"]
func()
This produces the following error message: It is not possible to invoke an expression on type 'object'. Neither Invoke or Call works.
How c...
I need to write a storage related app in Perl. The app needs to upload files from the local machine to some other storage nodes. Currently, the uploading method is FTP, but in the future it may be bittorrent or some unknown super-file-transferring method.
For every file that needs to be uploaded, there is a configuration file which de...
Here's my current thinking, but I dont know how to dispatch/execute it
my $key;
my @arraydata;
my %commandfunc{
"ab 1", \
foreach $k (keys %commandfunc){
if($something =~ /$k/){ #if $something match with a key string
$key= $k;
#some processing arraydata here;
}
}
#dispatching??
my $command = $commandfunc{$key}-...
Possible Duplicate:
How do I implement dispatch tables in Perl?
I have a hash table that contains commands such as int(rand()) etc.
How do I execute those commands?
...
Suppose I have something like the following:
class Point : geometry {
...
Point(double x, double y) {
}
double distanceTo(Line) {
}
double distanceTo(Point) {
}
}
class Line : geometry {
...
Line(double x, double y, double slopex, double slopey) {
}
double distanceTo(Line) {
}
double distanceTo(Poi...
What is the syntax for the hash value for a Perl object member subroutine reference in a dispatch table?
use lib Alpha;
my $foo = new Alpha::Foo;
$foo->bar();
my %disp_table = ( bar => ??? );
I want ??? to be the code reference for $foo->bar().
...