in reply to get keys from array of hashes
I don't like the "last if scalar(@{$columns}) == 10" bit. Since the keys could come in with any order, you're basically getting 10 random keys. It'll work, and the values should come in the same order so I'm not worried about that. But how do you know you'll get the 10 keys you want? I'd suggest either whitelisting a set of keys or blacklisting a set rather than using an explicit count.
Otherwise, it looks just fine. Though I'd just go ahead and make an array of columns instead of the array reference, as it would simplify the code a little:
my @columns; for my $key ( keys @{$AoH_records}[0] ) { push @columns, $key; last if scalar @columns == 10; } $csv->column_names( @columns );
(Though the array slice that AppleFritter mentions would be shorter still.)
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: get keys from array of hashes
by PerlSufi (Friar) on Aug 01, 2014 at 21:47 UTC |