Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Replacement for substr(Data::Dumper($x), 0, 4000)

by flexvault (Monsignor)
on Jan 17, 2012 at 14:37 UTC ( #948327=note: print w/replies, xml ) Need Help??


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

mje,

Maybe I'm missing something, but couldn't you just copy the beginning of the array to a new array, and then call Dumper with that array reference. Don't know what you would do if you have a hash????

use strict ; use warnings; use Data::Dumper; use Devel::Size qw(total_size); # Create a lot of data my @newdata = (); $newdata[10_000] = ""; for my $i ( 0 .. 10_000 ) { $newdata[$i] = "New" x $i; } print "\n\t\@newdata Size: ",total_size(\@newdata), "\n\n"; ## 150 +_345_584 on my system my @shortarray = (); for my $k ( 0 .. $#newdata ) { $shortarray[$k] = $newdata[$k]; if ( total_size(\@shortarray) > 400 ) { last; } ## use Maxchar +s } print Dumper( \@shortarray ); 1;

That way you keep the essence of the script!

Good Luck!

"Well done is better than well said." - Benjamin Franklin

Replies are listed 'Best First'.
Re^2: Replacement for substr(Data::Dumper($x), 0, 4000)
by mje (Curate) on Jan 17, 2012 at 16:03 UTC

    The data is a basically

    [[a,b],[c,d,e,...]]

    where c, d and e etc could contain further array references usually no deeper than 3 but the spec for this data does not restrict it to 3. I can basically copy the first array ref and then take N of the c,d,e etc where hopefully the result when Dumped is not longer than 4K. However, it is unlikely I can get an N which provides just over 4K (reducing the work in Dumper) as c, d, e can contain other scalars of varying lengths. An ideal would be picking N which gave just over 4K when Dumped. However, although this could truncate the dumped string less than 4K when N was too small it is still a viable solution as we only need the data accurate up to the truncation and its only 4K because that is the column size - the more the better though.

      mje,

        However, it is unlikely I can get an N which provides just over 4K...
      So pass Dumper 20KB or 100KB or whatever you think! It's still better than 16MB, and you control all the variables yourself!

      Thank you

      "Well done is better than well said." - Benjamin Franklin

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948327]
help
Chatterbox?
and the daffodils sway...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2018-07-16 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (349 votes). Check out past polls.

    Notices?