in reply to Replacement for substr(Data::Dumper($x), 0, 4000)

Does $Data::Dumper::Maxdepth fix things for you? If not (i.e. if you want to truncate a depth-first printout), then you may have to roll your own. You also *might* be able to wrap Data::Dumper::_dump() to keep track of how much it has produced, then use goto LABEL or die() to jump out when you have enough output. But Data::Dumper is partially XS, so that could be dangerous.

Replies are listed 'Best First'.
Re^2: Replacement for substr(Data::Dumper($x), 0, 4000)
by Tux (Canon) on Jan 17, 2012 at 15:34 UTC

    stealing _dump was my first hunch too, but is that is called on (sub)values, it will be very hard to catch the *total* size. And you will have to force using Dumpperl (a.o.t. using the much faster Dumpxs).

    { my $size = 0; my $org_dump = \&Data::Dumper::_dump; sub Data::Dumper::_dump { $size >= 4000 and return ""; my $s = $org_dump->(@_); $size += length $s; return $s; } }

    could be a crude start ...


    Enjoy, Have FUN! H.Merijn
Re^2: Replacement for substr(Data::Dumper($x), 0, 4000)
by mje (Curate) on Jan 17, 2012 at 15:38 UTC

    Maxdepth does not really help as I want the initial 4K to be correct (with no omissions) as far as it goes. _dump sounds interesting and I will look at it.