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
In reply to Re: Issues with Array of Hashes
by Lotus1
in thread Issues with Array of Hashes
by ciscomonkey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |