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


In reply to Re: Make CSV list from values in AoH by kcott
in thread Make CSV list from values in AoH by tel2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.