in reply to get keys from array of hashes
keys already returns a list, so you could directly assign that to an array and use splice to truncate it:
my @columns = keys $AoH_records->[0]; splice @columns, 10; $csv->column_names(\@columns);
If you don't care about truncating the array, you don't even need to save it, since ->column_names() will accept a list as well as an array reference:
$csv->column_names(keys $AoH_records->[0]);
BTW, on truncating arrays:
It's also possible to assign to $#columns to set it to a specific length, but unlike splice, this will pad it with new undefined elements if it's shorter.
The above splice call will produce a warning if the array has less than ten elements. To avoid that, do e.g. this:
use List::Util qw/min/; # ... splice @columns, min 10, scalar @columns
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: get keys from array of hashes
by PerlSufi (Friar) on Aug 01, 2014 at 21:35 UTC | |
by AppleFritter (Vicar) on Aug 01, 2014 at 21:43 UTC | |
by PerlSufi (Friar) on Aug 01, 2014 at 21:46 UTC |