Here's my current thinking, but I dont know how to dispatch/execute it
my $key;
my @arraydata;
my %commandfunc{
"ab 1", \&func1(\@arraydata),
"ab 2", \&func2(\@arraydata,
"ab 3", \&func3(\@arraydata)
};
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}->(\@arraydata);
Please correct my code.. Thanks alot
Hashes are initialized with regular parens (
( )), not curly brackets (those are for hash references.) And you initialize a hash with a list assignment. So the first part should be:The
=>operator is a little prettier than using a comma and has the added benefit of quoting barewords on the left side, if necessary.I'm not sure what you're trying to match in your loop (where does
$_come from?) But you can do something like this: