[ale] Perl parsing problem
Christopher Fowler
cfowler at outpostsentinel.com
Thu Nov 10 09:24:50 EST 2005
Perl Guru's:
I'm trying to create a config shell that runs in Linux that will use
XML-RPC to configure our embedded device. The XML-RPC thing is
complete. What I'm working on now is parsing the command line.
here is my code:
--------------------------------
sub prompt {
print "# ";
my $cmd = <STDIN>;
chomp $cmd;
$cmd =~ m/^(.+?)\s(.+?)\s(.+?)$/;
my $verb = $1;
my $noun = $2;
my $cmdline = $3;
print "[[$verb]]\n";
return ($verb, $noun, $cmdline);
}
-------------------------------
$1, $2, and $3 substitutions fail when there is only one verb like
'exit'. Verbs can be 'show, set, add, delete, or exit'. Nouns can be
'port, user, vtun, snmp, etc.' So to show port 1's config I use 'show
port 1' To show all ports I use 'show port'. I guess I could simply
use split and split on \s boundaries. for $cmdline I need to be
smarter. Some items have descriptions that can include a space and I
will want to cut $cmdline into arguments.
'set system location "Buford Development"'
verb = set
noun = system
arg[0] = location
arg[1] = 'Buford Development'
So I'm trying to do shell like parsing. I bet there is a module that
does all this for me. If not can someone point me in the best
direction.
Thanks,
Chris
More information about the Ale
mailing list