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
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
OUTPUT:use strict; use warnings; use Data::Dump qw/pp dd/; my @AoH = ( {AB => 100, NN => 200, XYZ => 400}, {AB => 100, XYZ => 400, MM => 300}, { map { ("A$_" => $_) } "A".."C" } ); my %H; %H = (%H,%$_) for @AoH; dd keys %H; my %count; map { map { $count{$_}++ } keys %$_ } @AoH; dd sort { $count{$b} <=> $count{$a} || $a cmp $b } keys %count;
("XYZ", "NN", "MM", "AC", "AA", "AB") ("AB", "XYZ", "AA", "AC", "MM", "NN")
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 reply to Re: Writing hashes as records to a CSV file
by LanX
in thread Writing hashes as records to a CSV file
by Serene Hacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |