in reply to Issues with Array of Hashes

Does the code you posted above work correctly, or is this the code that is broken? I installed the module and your above code works verbatim.

If the problem is in other code that you're not showing, it seems as though you're going to have to post it.

Replies are listed 'Best First'.
Re^2: Issues with Array of Hashes
by ciscomonkey (Novice) on Jan 20, 2017 at 18:43 UTC
    Interesting that the above code doesn't kick out the error for you. Using the above code (including showing the ref of each):
    use Modern::Perl; use Text::CSV::Slurp; 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'} ); print "\$ref->{'items'} is " . ref( $ref->{'items'} ) . "\n"; foreach my $item ( @{ $ref->{'items'} } ) { print $item->{'name'} . " is " . ref( $item ) . "\n"; } my $csv = Text::CSV::Slurp->create( input => $ref );
    Gets the error for me on both mac and ubuntu boxes: Error on Mac:
    $VAR1 = [ { 'name' => 'item1' }, { 'name' => 'item2' } ]; $ref->{'items'} is ARRAY item1 is HASH item2 is HASH Need an an array of hashes input to create CSV from at /usr/local/Cell +ar/perl/5.24.0_1/lib/perl5/site_perl/5.24.0/Text/CSV/Slurp.pm line 53 +.
    And on Ubuntu box:
    $VAR1 = [ { 'name' => 'item1' }, { 'name' => 'item2' } ]; $ref->{'items'} is ARRAY item1 is HASH item2 is HASH Need an an array of hashes input to create CSV from at /usr/local/shar +e/perl/5.22.1/Text/CSV/Slurp.pm line 53.