ciscomonkey has asked for the wisdom of the Perl Monks concerning the following question:
I have multiple steps doing this same thing with no issue, and a quick Dumper output from those looks to be the exact same as the Dumper output from this code above. e.g. $VAR1 = [ {'key' => 'val' },{ 'key' => 'val' } ]; however it keeps coming back with "Need an an array of hashes input to create CSV from" and I'm a little lost as to why. I've even compared against those that work with the following: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'} ); my $csv = Text::CSV::Slurp->create( input => $ref->{'items'} );
Which yields:print "\$ref->{'items'} is " . ref( $ref->{'items'} ) . "\n"; foreach my $item ( @{ $ref->{'items'} } ) { print $item->{'name'} . " is " . ref( $item ) . "\n"; }
And both look the same. I'm hoping I'm just missing something really simple here, but any help is appreciated.$ref->{'items'} is ARRAY item1 is HASH item2 is HASH
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Issues with Array of Hashes
by stevieb (Canon) on Jan 20, 2017 at 16:25 UTC | |
by ciscomonkey (Novice) on Jan 20, 2017 at 18:43 UTC | |
|
Re: Issues with Array of Hashes
by Lotus1 (Vicar) on Jan 20, 2017 at 18:40 UTC | |
by ciscomonkey (Novice) on Jan 20, 2017 at 18:46 UTC | |
by Lotus1 (Vicar) on Jan 20, 2017 at 19:30 UTC | |
by ciscomonkey (Novice) on Jan 21, 2017 at 05:06 UTC |