in reply to Make CSV list from values in AoH
Hello tel2,
Here is a way to do it with help from the Text::CSV::Slurp module.
#!/usr/bin/env perl use strict; use warnings; use Text::CSV::Slurp; my @aoh = ( { name => 'Adam', age => 0 }, { name => 'Bob', age => 10 }, { name => 'Cat', age => 20 } ); open my $fh, '>', 'output.csv' or die $!; if( scalar @aoh > 0 ){ my $csv = Text::CSV::Slurp->create( input => \@aoh, always_quote => 1, quote => "'" ); print $fh $csv; } else { print $fh "''"; } $fh->close; exit;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Make CSV list from values in AoH
by tel2 (Pilgrim) on Aug 20, 2018 at 01:27 UTC |
In Section
Seekers of Perl Wisdom