Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Dumping opaque objects

by syphilis (Archbishop)
on Jan 24, 2022 at 10:58 UTC ( [id://11140787]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Dumping opaque objects
in thread Dumping opaque objects

Hi hv,

I was able to get a Dumper() that appears more meaningful (to me, at least) with:
## dumper.pl ## use strict; use warnings; use Data::Dumper; use Math::GMP; my $x = [ Math::GMP->new(101), Math::GMP->new(203), Math::GMP->new(116 +7) ]; print Dumper("@$x"); __END__ C:\_32\pscrpt>perl dumper.pl $VAR1 = '101 203 1167';
However, I'm not familiar with Data::Dumper and I've no idea if that's of any use to you.

Cheers,
Rob

Replies are listed 'Best First'.
Re^4: Dumping opaque objects
by hv (Prior) on Jan 24, 2022 at 16:04 UTC

    Thanks Rob, that's essentially the sort of thing I currently need to do, but it requires knowing the exact structure to be dumped and walking it myself. I also want to distinguish between GMP objects and simple integers - particularly to spot when something that should be GMP is not or v.v. - so I'd end up needing to write most of Data::Dumper myself. I had hoped somebody would already have done that for me (and that someone here would have used it).

    My CPAN-fu is minimal, but of the 2,520 matches on metacpan for 'dump', a quick scan of the first 100 threw up some maybes such as Data::Printer (which cares mostly about coloured output) and Data::Dump::Streamer (which cares mostly about structure recreatability via eval). I also spotted a cross-reference to Data::Rmap, which might offer a sane way to roll my own. I'll try some of those and see what I get.

      I also want to distinguish between GMP objects and simple integers

      Yes - inside my own gmp-based modules I often want to know about such things.
      I normally use XS or Inline::C subroutines for this.

      In pure perl code, as you may already be well aware, the ref() function will go a long way to providing useful information about references and module objects.
      use warnings; use Math::BigInt; use Math::GMP; my $v = 9; my %h = (foo => $v); for (\%h, [$v], \$v, Math::GMP->new($v), Math::BigInt->new($v), $v) { ref($_) ? print ref($_), "\n" : print "Not a reference\n"; } __END__ Outputs: HASH ARRAY SCALAR Math::GMP Math::BigInt not a reference
      You can also use the B module instead of XS/Inline::C to determine whether a scalar is an IV or an NV or a PV or a combination thereof.

      If you want more info on any of these aspects, just ask.
      (I don't want to annoy you by banging on with stuff that you already know (or stuff that you're not particularly interested in).

      Cheers,
      Rob

        Thanks Rob, I am indeed pretty conversant with that stuff. The aim here is to avoid writing my own dumping module just to get around the lack of a single feature in the standard one - there is a forest of them already on CPAN, it seems very likely there would already be one ideal for my needs (or needing at most minor topiary).

        See also my update on the root post where I describe what I'm currently experimenting with via Data::Printer: that is working at least well enough to let me get further with the code I was originally trying to write.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 18:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found