Hi, I don't think that there is a real out-of-memory problem, but surely a problem with accuracy. Sorry, I am too tired to decode your program right now, but it looks a little bit C-ish to me. Something more terse and Perlish to start from might be:

#!/usr/bin/perl use strict; chomp (my $equation = <DATA>); my @stack; foreach ( split(/\s*,\s*/, $equation) ) { push(@stack,$_), next if /\d+/; die "stack underrun" if @stack < 2; my ($val1, $val2) = (pop(@stack), pop(@stack)); push(@stack, $val1 + $val2), next if $_ eq '+'; push(@stack, $val1 * $val2), next if $_ eq 'x'; die "undef. operator ($_)"; } print "Result (stack): ", join(", ", @stack), "\n"; __DATA__ 1,2,3,4,+,5,+,x,6, ...... x,x,x,x,x,9164,x,+,9165,9166,91 <--- you +r input as a single line Result (stack): 1, 144, 1.9792773969506e+27, 6.22437334578068e+26, 5.7 +7209920038837e+273, 8966, 4.97957520221034e+261, 9165, 9166, 91
Seems that the equation is not complete? Furthermore, as you can see, the usual built-in precision might not be sufficient for your purpose. So you should have a look at e.g. Math::BigInt too.


In reply to Re: Out of memory. by Perlbotics
in thread Out of memory. by dneedles

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.