Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

perl dumper to output tabulated (csv, tab delimitde) format

26 views
Skip to first unread message

Joe

unread,
Nov 10, 2020, 3:06:21 PM11/10/20
to
My goal was to convert a very large XML file to CSV or tab delimited text.
I used these to parse XML file:
my $tpp = XML::TreePP->new();
my $tree = $tpp->parsefile("$fileName");
my $text = Dumper( $tree );
but the output was all in JSON format.

Is it possible for perl DUMPER to output flat files in csv or tab delimited formats?

Thanks!
j

Keith Thompson

unread,
Nov 10, 2020, 4:11:49 PM11/10/20
to
Data::Dumper's output is not JSON. It's Perl syntax. It doesn't seem
to have any options for producing something else.

If you wanted JSON output, you could use the JSON package.

There are a number of packages that handle CSV, including Text::CSV.

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

$Bill

unread,
Nov 10, 2020, 4:59:33 PM11/10/20
to
It should be simple enough to convert from a Perl hash to whatever form
you want. What does a sample of output look like? I assume $tree is a hash ref
that contains an array/bunch of hashes that you could easily convert to CSV or tab
separated text lines.

do foreach key in hash kinda thingy. Maybe could get complicated if there are
sub-hashes or irregular data format.

Henry Law

unread,
Nov 10, 2020, 6:36:28 PM11/10/20
to
On Tue, 10 Nov 2020 12:06:16 -0800, Joe wrote:

> used these to parse XML file:
> my $tpp = XML::TreePP->new();
> my $tree = $tpp->parsefile("$fileName");
> my $text = Dumper( $tree );
> but the output was all in JSON format.

Which "Dumper" is that? It would help if we saw real code, especially
"use" statements. I ask because Data::Dumper::Dumper won't output JSON
or CSV or any other particular format: it dumps Perl data structures
using Perl code to do it, so it will dump whatever your "parsefile"
method returns (probably a multi-layer hashref, but not necessarily).

--
Henry Law n e w s @ l a w s h o u s e . o r g
Manchester, England

George Bouras

unread,
Nov 11, 2020, 2:14:21 PM11/11/20
to
send a sample of this xml

Joe

unread,
Nov 30, 2020, 10:22:51 PM11/30/20
to
On Tuesday, November 10, 2020 at 3:11:49 PM UTC-6, Keith Thompson wrote:
> Joe <julian...@gmail.com> writes:
> > My goal was to convert a very large XML file to CSV or tab delimited text.
> > I used these to parse XML file:
> > my $tpp = XML::TreePP->new();
> > my $tree = $tpp->parsefile("$fileName");
> > my $text = Dumper( $tree );
> > but the output was all in JSON format.
> >
> > Is it possible for perl DUMPER to output flat files in csv or tab
> > delimited formats?
> Data::Dumper's output is not JSON. It's Perl syntax. It doesn't seem
> to have any options for producing something else.

Thank you Keith, you hit the key. I will need to re-approach the problem.
j

Dr Eberhard W Lisse

unread,
Dec 4, 2020, 2:26:14 AM12/4/20
to
0 new messages