Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: In need of a Dumper that has no pretentions to being anything else.

by fergal (Chaplain)
on Feb 23, 2005 at 06:27 UTC ( #433595=note: print w/ replies, xml ) Need Help??


in reply to Re^4: In need of a Dumper that has no pretentions to being anything else.
in thread In need of a Dumper that has no pretentions to being anything else.

Apart from the "Attempt to free unreferenced scalar" stuff (which seems like a bug) what's wrong with this? Math::Pari objects are just a simple scalar blessed into a class as far as Perl is concerned. Nothing is going to dump them out as anything more sensible unless it specififcally knows how to understand Math::Pari objects.

You'll need to play with DD's Freezer stuff to get anywhere on that.


Comment on Re^5: In need of a Dumper that has no pretentions to being anything else.
Re^6: In need of a Dumper that has no pretentions to being anything else.
by BrowserUk (Pope) on Feb 23, 2005 at 06:38 UTC
    Nothing is going to dump them out as anything more sensible unless it specififcally knows how...

    What I'm doing is:

    perl> use Math::Pari qw[factorint];; perl> $f = factorint 1000000;; perl> use overload;; perl> print overload::StrVal $f;; Math::Pari=ARRAY(0x22ac84)

    Once you kick away the overloading, you can see that you have an array and then dump is elements by accessing them, recursing if need, be until you get a non-reference value returned.

    I think this should work for any overloaded reference?


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
      One problem there is that Math::Pari integers are not just a ref to an integer that's been overloaded. When you see
      bless( do{\(my $o = 33884400)}, 'Math::Pari')
      coming out of DD, the 33884400 here is a pointer to a memory location holding C structure that came out of the Pari lib. Simply printing out whatever you find after derefencing everything won't work. You need something that understands Math::Pari or you need to use DD's Freezer facility to make DD understand Math::Pari.

        With a couple of lines addition to disable the overload::StrVal once you unwind the overloaded objects down to a scalar, Dumpvalue handles Math::Pari objects quite well.

        P:\test>p1 perl> use Math::Pari qw[ :int factorint sqrtint divisors PARI ];; perl> use Dumpvalue;; perl> $f = factorint 1000000;; perl> { local $\; $d=Dumpvalue->new; $d->veryCompact(1); $d->dumpValue +( $f ) };; 0 Math::Pari=ARRAY(0x1a37364) 0 2 1 5 1 Math::Pari=ARRAY(0x1a3728c) 0 6 1 6

        Another tweak to allow it to format overlaoded arrays as it would an ordinary array, and it'll be perfect.

        Then I'll try changing the circularity test to use a more compact method of storing the reference addresses and I'll have everything was looking for. :)


        Examine what is said, not who speaks.
        Silence betokens consent.
        Love the truth but pardon error.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://433595]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2015-07-07 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls