Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Writing hashes as records to a CSV fileby LanX (Saint) |
on Dec 08, 2021 at 23:27 UTC ( [id://11139483]=note: print w/replies, xml ) | Need Help?? |
> but can one do it directly (using Text::CSV) ie. without figuring out the superset of keys myself I searched thru the documentation of Text::CSV but couldn't find that. But I'm confident Tux as one of the maintainers will know. > I could do this "manually" as it were, Merging hashes is not complicated in Perl: after %H = (%H,%$_) for @AoH you'll have the superset in keys %H More importantly you can keep control over the order of columns created. (like ordering by count) Do you really want to leave that to Text::CSV, which most probably will be random?
Cheers Rolf
update x2OUTPUT:
NB: "AB" is last in the first result, even that it appears in each record. The second result however will order the columns first by count and then by alphabetic order. YMMV...
In Section
Seekers of Perl Wisdom
|
|