sub init_commands { # Fill %Commands hash for parsecommands # %Commands{commandname}{pattern} = # %Commands{commandname}{function} = ['modulename', [['name', number of arguments]] # %Commands{commandname}{syntax} = $Commands{'log'}->{'pattern'} = '^log (.*)$'; $Commands{'log'}->{'function'} = ['', ['createlog', 1]]; $Commands{'log'}->{'syntax'} = 'log '; $Commands{'modules saveall'}->{'pattern'} = '^modules saveall$'; $Commands{'modules saveall'}->{'function'} = ['', ['savemodules', 0]]; $Commands{'modules saveall'}->{'syntax'} = 'modules saveall'; $Commands{'modules loadall'}->{'pattern'} = '^modules loadall ([\w\.]+)$'; $Commands{'modules loadall'}->{'function'} = ['', ['loadmodules', 1]]; $Commands{'modules loadall'}->{'syntax'} = 'modules loadall '; ... and so on.. } #### while( my ($command, $params) = each %Commands) { # debug("parselocalcommand: Command: $command\n"); if(substr($data, 0, length($command)) eq $command) { my $pattern = $params->{'pattern'}; if(my @res = $data =~ $pattern) { if($#+ == $params->{'function'}[1][1]) { my $answer; if($params->{'function'}[0] eq '') { $answer = &{$params->{'function'}[1][0]}(@res); } else { $answer = modulemethod($params->{'function'}[0], $params->{'function'}[1][0], @res); } if($answer) { printandprompt($answer); last; } } } else { printandprompt("Syntax: #" . $params->{'syntax'} . "\n"); } } }