Works for me...?

I read the problem description you gave (summing the series), and wrote a "1-liner" (iterative 'bashing') which seems to work exactly as you describe. I am using the ".." operator just as you are, so I don't think you need to use the "C" style "for" loop. Not yet sure why things aren't working the same for you (am using 5.8.8, here, as well). Original "1-liner format:"

perl -e 'use bigrat;for my $n (1..5){my $s=0;for my $i (1..$n) {$s+=($ +n+1-$i)/$i} push @nums, $s->numerator; push @dens, $s->denominator; $ +num=$s->numerator; $den=$s->denominator; print "n = $n, s = $s, num=$ +num, den=$den\n";} print "nums=",(join ", ",@nums), "\n"; print "dens +=",(join ", ",@dens),"\n";'
Or pretty-i-fied:
#!/usr/bin/perl -w use bigrat; for my $n (1 .. 5) { my $s = 0; for my $i (1 .. $n) {$s += ($n + 1 - $i) / $i} push @nums, $s->numerator; push @dens, $s->denominator; $num = $s->numerator; $den = $s->denominator; print "n = $n, s = $s, num=$num, den=$den\n"; } print "nums=", (join ", ", @nums), "\n"; print "dens=", (join ", ", @dens), "\n";
Did you convert some 'bignum' type to an integer somewhere? I'll have to study your code more closely to find out where it's breaking, but thought I'd at least offer something that seemed to do what you wanted in the way you wanted...:-)
-Linda

In reply to Re: 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.