This little snippet reminds me of the old days when I was still in college. I was writting a Java applet that would graph a polynomial expression, and was having quite a hard time getting it finished. There were many conditions i had to consider ... one polynomial, two, or more ... (Java isn't very good at that sort of thing).

Then, eduardo pops by my computer and says "Oh! You should be doing that with Perl and Tk!" And he promptly sat down at the computer beside me and started typing away (at about 75wpm, i might add).

About 15 minutes later, he said "here, look at this" and i watched in amazement as his quick prototype whipped my Java applet's butt, in about 10 lines of code!

After that, I was sold on Perl!

I do have some suggestions for your code - first, please use strict. I know you don't need it, but for the sake of those new to Perl, it's just a good thing to demonstrate. Second, I would opt for my $a = join('',@ARGV); or even my ($a) = @ARGV; instead of my $a = "@ARGV";, simply because enclosing an array in quotes is confusing, again, to those new to Perl. Newbies see code like that and wonder why code like this doesn't do what they think it will:

my $ref = { foo=>'bar' }; my $clone = "$ref";
And last, this is a good candidate for the -l ( dash el, not dash one) flag:
#!/usr/local/bin/perl -lw
(yes, please use warning too) -l appends a new line at the end of your output, so this allows you to drop having to print a new line at the end. Laziness ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

In reply to (jeffa) Re: Simple calculator by jeffa
in thread Simple calculator by Juerd

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.