Hello Monks,
SOLVED
I want to get the keys from an Array of Hashes and put them into an array ref for using as column names with Text::CSV. All of the keys will be the same so I just need the one hash's set of them. I even know how many there will be- but I want to know if there is a better way than this:
use strict;
use warnings;
use Text::CSV;
my $csv = Text::CSV->new( { binary => 1, eol => "\n" } );
my $file = "records.csv";
open( my $csv_fh, '>', $file ) or die "Unable to open $file for writin
+g: $!\n";
my $AoH_records = [
{
foo => 'bar',
key => 'value',
},
];
my $columns = [];
for my $key ( keys @{$AoH_records}[0] ) {
push @{$columns}, $key;
last if scalar(@{$columns}) == 10;
}
$csv->column_names( $columns );
Any insight is greatly appreciated :)