develooper Front page | perl.perl5.porters | Postings from January 2001

Data::Dumper suggestion

From:
Rich Morin
Date:
January 16, 2001 11:38
Subject:
Data::Dumper suggestion
Message ID:
p0500193bb68a23e4512f@[192.168.168.205]
I am using Data::Dumper in conjunction with XML::Simple (using the
latter's "forcearray" option).  This combination works quite well,
by and large, save that the output tends to sprawl quite a bit.  I
have worked up my own kludge to shorten the output:

sub dumpit {            # (Terse) structure dump
   my ($data) = @_;
   my $tmp;

   local $Data::Dumper::Indent = 1;

   $tmp =  Dumper($data);
   $tmp =~ s@{\n\s+'@{ '@g;
   $tmp =~ s@\n\s+}@ }@g;
   $tmp =~ s@\[\n\s+('[^']+')\n\s+]@[ $1 ]@g;
   $tmp =~ s@\[\n\s+([0-9]+)\n\s+]@[ $1 ]@g;
   print $tmp;
}

This produces output of the form:

$VAR1 = { 'rdm_note' => [
     { 'admin' => [ '?' ],
       'name' => [ '/kernel' ],
       'see_also' => [
         { 'content' => '?',
           'status' => 'primary',
           'section' => '?' },
           ...

I don't know that enough others would want terse format to
make modifying Data::Dumper worthwhile, but my hack might
make an interesting note in the man page.


While I'm on the subject, I will note that the man page
heading on my (FreeBSD 4.1) system comes out as:

   Data::Dumper::DUserrContributed Perl DocumData::Dumper::Dumper(3)

which seems a bit broken (:-).

Finally, many thanks for all of your good work over the years!

-r
-- 
--
http://www.cfcl.com/rdm
email: rdm@cfcl.com
phone: +1 650-873-7841



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About