Hello Wise and Helpful Monks, I have a question for you that troubles me...

Ok, so I got bored and I thought I would make a calculator as one of my first programs. I figured out how to make it do anything, but you had to change the script everytime you had a different problem or operator. Then, as time went on I learned more as we all do. I learned the concept of "<STDIN>" so that I wouldn't have to change the script for new variables because the user would input them. I ended up with this and this is far as I have gotten in my problem.
#!/usr/bin/perl $a="<STDIN>"; $b="<STDIN>"; print "$a+$b\n";

I have a problem though. As you can see I need to change the script if I want any other operation such as: subtraction, powers, multiplication, division, etc...
I haved asked in the CB and searched my books and the web but in vain, because I cannot find a way to make the user input the operation. I thought that this idea might look like....

$operator="<STDIN>"

but I was obviously and expectedly wrong.
Any ideas on how I can get this little operation input problem fixed?


-Variable_B

In reply to Inputing an Operator is it possible? by $Variable_B

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.