Sorry I was unclear. By "original formula", I mean the formula that generated the series you gave as an example of what you wanted to generate. I.e.:
(Series 1) 30 29 1 ---- + ---- + ... + ---- 1 2 30
From that, you said that you wanted to be able to compute the "general case for 'n', where n is the number of items in a series that looks similar to the example above I.e:
(Formula for Series 1) ( (n+1-k) ) Sum ( ------- ) for k = (1..n); ( k )
If you were computing the sum for 'n-1', wouldn't you want the sum:
(Series 2) 29 28 1 ---- + ---- + ... + ---- 1 2 29
That's not what your code generates, either. That's what I meant by 'fixing' the code -- making it consistent with which-ever series you wanted (top one for 'n' or bottom one for 'n-1'). But the program you implemented doesn't generate either series because it doesn't implement the formula to generate that series but instead, for n=30, generates the series:
(Series 3) 1 2 30 ---- + ---- + ... + ---- 29 28 0
That series is backwards from your original example, the code always divides by zero at the end the inner "for-loop", and skips the inner for-loop entirely, on the first iteration through the outer for-loop, making the sum, "$s", equal to "0". So the first time through the outer loop, you try to call $s->numerator & $s->denominator, but you've called them when $s=0 and no calculations have been done, thus the exception.

Where you wanting to discover something different? :-)


In reply to Re^3: issues using bigrat by perl-diddler
in thread issues using bigrat by pc88mxer

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.