in reply to Issues with Array of Hashes

Looking at the source code for the create method in Text::CSV::Slurp I see the die message you reported at the beginning.

sub create { my ( undef, %arg ) = @_; die "Need an an array of hashes input to create CSV from" unless exists $arg{input} && ref( $arg{input} ) eq 'ARRAY' && ref( @{ $arg{input} }[0] ) eq 'HASH';

One of those three things must be wrong with the array of hashes you are passing. You'll need to test your Arrays of Hashes before calling create. To start you could set up some tests to tell you when it fails. Something like:

use strict; use warnings; use Data::Dumper; sub generate { my %inline; $inline{'total'} = 2; $inline{'items'} = [ { 'name' => 'item1' }, { 'name' => 'item2' } ]; return \%inline; } my $ref = &generate(); print Dumper( $ref->{'items'} ); die "failed exists at $ref->{'total'}" unless exists $ref->{'items'}; die "not ARRAY at $ref->{'total'}" unless ref( $ref->{'items'} ) eq 'ARRAY'; die "not HASH at $ref->{'total'}" unless ref( @{ $ref->{'items'} }[0] ) eq 'HASH'; print "ok"; #my $csv = Text::CSV::Slurp->create( input => $ref->{'items'} ); __DATA__ $VAR1 = [ { 'name' => 'item1' }, { 'name' => 'item2' } ]; ok

Replies are listed 'Best First'.
Re^2: Issues with Array of Hashes
by ciscomonkey (Novice) on Jan 20, 2017 at 18:46 UTC
    Using that code, it makes it all the way through:
    $VAR1 = [ { 'name' => 'item1' }, { 'name' => 'item2' } ]; ok

      Yes it ran fine for me, as I showed with the ok at the end of my code. Also, your original code ran fine for me. What version of the modules are you using?

        Looks to be 1.03.