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:

Replies are listed 'Best First'.
Re^2: get keys from array of hashes
by PerlSufi (Friar) on Aug 01, 2014 at 21:35 UTC
    Thanks AppleFritter,
    Your method SHOULD work, but I am just now realizing that the  ->column_names method itself is not working for me- but using  ->print($csv_fh, $columns) does?
    UPDATE: This is what I did for me to get it work, I am not sure why the column_names method isn't working for me though..
    my $columns = [ keys $AoH_records->[0] ]; $csv->print( $csv_fh, $columns );

      You're welcome! *tips hat*

      What do you mean by "not working for me"? As far as I can tell, ->column_names() is not for printing column names to a CSV file; quoting Text::CSV's documentation:

      column_names

      Set the keys that will be used in the getline_hr () calls. If no keys (column names) are passed, it'll return the current setting.

      So I'd say ->print() is the way to go, yes.

        Gotcha, Thanks a bunch :)