The first and perhaps hardest thing to do is to parse the input. You need to write some form of lexer to tokenize the input. This can be done with regexes eating up progressively the input (with the /g modifier).

But rather than trying to explain myself probably in a poor fashion, I would suggest that you take a look at chapter 8 ("Parsing") of Mark Jason Dominus' excellent book, Higher Order Perl (http://hop.perl.plover.com/). This chapter is available on-line here: http://hop.perl.plover.com/chap08.html.

You probably don't need to go in all the complexity of that chapter, but you should find a lot of ideas which you can then implement in your own simple way for what you need.

Je suis Charlie.

In reply to Re: How would you solve a user-inputted simple one-variable Linear Equation by Laurent_R
in thread How would you solve a user-inputted simple one-variable Linear Equation by nat47

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.