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
In reply to Re: get keys from array of hashes
by AppleFritter
in thread get keys from array of hashes
by PerlSufi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |