[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Thu, 10 Nov 2005 09:41:01 -0500 -->
- <!--x-from-r13: ccbyfgen ng tznvy.pbz (Buvyvc Bbyfgen) -->
- <!--x-message-id: [email protected] -->
- <!--x-reference: [email protected] --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] Perl parsing problem -->
- <li><em>date</em>: Thu, 10 Nov 2005 09:41:01 -0500</li>
- <li><em>from</em>: ppolstra at gmail.com (Philip Polstra)</li>
- <li><em>in-reply-to</em>: <<a href="msg00159.html">[email protected]</a>></li>
- <li><em>references</em>: <<a href="msg00159.html">[email protected]</a>></li>
- <li><em>subject</em>: [ale] Perl parsing problem</li>
You can then check to see if $noun and $cmdline are defined to know how many
parameters were passed.
On 11/10/05, Christopher Fowler <cfowler at outpostsentinel.com> wrote:
>
> 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
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> <a rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale">http://www.ale.org/mailman/listinfo/ale</a>
>
-------------- next part --------------
An HTML attachment was scrubbed...
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00161" href="msg00161.html">[ale] Perl parsing problem</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00159" href="msg00159.html">[ale] Perl parsing problem</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00159.html">[ale] Perl parsing problem</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00161.html">[ale] Perl parsing problem</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00159.html">[ale] Perl parsing problem</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00161.html">[ale] Perl parsing problem</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00160"><strong>Date</strong></a></li>
<li><a href="threads.html#00160"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>