jabowery has asked for the wisdom of the Perl Monks concerning the following question:

Doing a dump of a data structure containing some Math::BigRat numers, one of them came out as:

Math::BigRat->new(1571564245790041077296625940243395969525186964287593 +983211702071746502379495623702577687858610948113768329213254446858777 +462774205807704907534468051879076153966236613373983285049528141164401 +804491277534042420588175951527609420679646968472291614616493189613724 +30678659/460397631724414375288203319974097111671726091486872993814540 +858035284745439761138909372513995598452763793523966663078798210624544 +163215635719624749415998193424763330332330636532827342407051247856305 +66719533434246383626808498436777490000000000000000000000000000000000)

When I eval (or do) this file (with Math::BigRat loaded of course), it fails silently. When I remove this line, it succeeds.

Any ideas?

PS: This is rather annoying as this data appears in the audit logs and causes my log audit tools to fail silently. I can't have corrupt data appearing in my logs and, BTW, this isn't even corrupt data, really.

Replies are listed 'Best First'.
Re: Math::BigRat Dump Fails on Eval
by SuicideJunkie (Vicar) on Apr 23, 2014 at 20:19 UTC

    Please fix your post, it is breaking the formatting.

    As to your problem, consider the following code:

    use Math::BigRat; my $num = Math::BigRat->new(157156424579004107729662594024339596952518 +6964287593983211702071746502379495623702577); my $num2 = Math::BigRat->new('1571564245790041077296625940243395969525 +186964287593983211702071746502379495623702577'); print "Numeric: $num\n"; print "Stringy: $num2\n";
    c:\>perl test.pl Numeric: 1571564245790040000000000000000000000000000000000000000000000 +000000000000000000000000 Stringy: 1571564245790041077296625940243395969525186964287593983211702 +071746502379495623702577 c:\>_

    In the first case, you're trying to make a constant number which has to be passed in to bigrat as a float. In the second case, bigrat gets all the digits nicely.

      So I guess what you're saying is I need to fix the interface between Data::Dump and Math::BigRat -- because it is in that interface that the quotes are being left out.

      UPDATE: There was a buggy filter callback in my call to dumpf:

      sub{my ($ctx,$self)=@_;$ctx->object_isa('Math::BigRat')?{dump=>"Math::BigRat->new($self)"}

      As for the formatting of the original post, you didn't specify what was 'broken' about the formatting but I did notice that there was no download link, and I put some white space into the source (CR before and after the code tags) to fix that.

      If it is the lack of wrapping you are referring to, the only help I found was in the "Writeup Formatting Tips" where they discuss only "Display Settings", which places the burden on the reader to specify auto-wrapping.

Re: Math::BigRat Dump Fails on Eval
by syphilis (Archbishop) on Apr 24, 2014 at 03:08 UTC
    Doing a dump of a data structure containing some Math::BigRat numers, one of them came out as:

    Math::BigRat->new(15715642....00000)


    What was the output you wanted/expected to see ?

    When I eval (or do) this file (with Math::BigRat loaded of course), it fails silently. When I remove this line, it succeeds.

    That's not a very meaningful description of what happens(to me, at least). Better if you could post a minimal script that demonstrates the problem.

    Cheers,
    Rob