Hi

For a script I am writing I have a need to have a command interpreter at a server so that it knows what I want to do. There are a whole swag of different things I'm wanting to tell it and all the commands have different formats and argument requirements etc.

i.e.
Log this ontime that
create this with thing1 thing2 thing3
etc. etc.

I am getting a whole range commands now and the way I've delt with it is firstly using a switch that checks the first key word i.e. /^log/ and then farm them off to now overwieldly subroutines the are large combinations of if's and reg ex's to work out which particular command format was used.

I'm thinking there has to be a prettier way, I mean it all works...its just not....'nice'. Is there a module or similar that is designed for this purpose so that after defining acceptable log formats it auto throws the bads ones and can dump acceptable results to the correct subroutines?

How have others solved this problem? Would say having a hash of subroutines as keys and reg ex's as the values and searching them on input be better? I'm guessing that would make insertion of new commands easier than trawling through a huge subroutine for the right place to insert.

Any incite would be appreciated =)..

Regards Paul.

In reply to command input processing by thekestrel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.