in reply to Make CSV list from values in AoH

G'day tel2,

How's things on your side of the ditch; it's cold, wet and windy on my side. :-(

I saw your exchanges with LanX. I believe the following script addresses all the issues raised in that subthread as well as the update to your OP. It:

#!/usr/bin/env perl use strict; use warnings; my @AoH_1 = ( { name => 'Ant', age => 0 }, { name => '0', age => 10 }, { name => 'Bob', age => 20 }, { name => 0, age => 30 }, { name => 'Cat', age => 40 }, { name => '', age => 50 }, { name => 'Dog', age => 60 }, { name => undef, age => 70 }, { name => 'Eel', age => 80 }, { age => 90 }, { name => 'Fox', age => 99 }, ); my @AoH_2 = (); my $q = "'"; for (\@AoH_1, \@AoH_2) { my @AoH = @$_; print 'Elements in AoH: ', 0+@AoH, "\n"; my $csv; if (@AoH) { $csv = join ',', map { defined $AoH[$_]{name} ? "$q$AoH[$_]{name}$q" : "$q$q" } 0 .. $#AoH; } else { $csv = "$q$q"; } print "CSV: $csv\n"; }

Output:

Elements in AoH: 11 CSV: 'Ant','0','Bob','0','Cat','','Dog','','Eel','','Fox' Elements in AoH: 0 CSV: ''

— Ken

Replies are listed 'Best First'.
Re^2: Make CSV list from values in AoH
by tel2 (Pilgrim) on Aug 20, 2018 at 01:05 UTC
    G'day Ken,

    Similar weather here, mate.

    Thanks for your comprehensive solution.

    tel2