Hi, maybe this is helpful? (Update: modified as suggested by the master)

use strict; use warnings; use Text::CSV_XS 'csv'; my @records = map { my %record; for ( split "\n" ) { my ($key, $val) = split ': '; $record{$key} = $record{$key} ? join ', ', $record{$key}, $val + : $val; }; \%record; } split "\n\n", do { local $/; <DATA> }; my @col_names = qw(cn host description env keyWords l sysadm1 sysadm2 +administratorContactInfo nsHardwarePlatform version); my @rows = map { my $record = $_; [ map { $record->{$_} || '' } @col_n +ames ] } @records; csv( in => \@rows, headers => \@col_names, out => '/tmp/foo.csv' ); __DATA__ cn: epcpc5 host: epcpc5 description: research server l: Narnia Data Center cn: epcmsp host: epcmsp description: Service Processor l: Narnia Data Center cn: post62a host: post62a description: network printer keyWords: netprinter l: Narnia Data Center cn: tst401 host: tst401 host: tst401.narnia.org host: srv1ck41 description: Test Application Server env: test keyWords: linuxserver keyWords: nonprod keyWords: localperl keyWords: sudoers l: Data Center, Narnia sysadm1: aslan administratorContactInfo: sciops nsHardwarePlatform: DellR730

Output:

$ cat /tmp/foo.csv cn,host,description,env,keyWords,l,sysadm1,sysadm2,administratorContac +tInfo,nsHardwarePlatform,version epcpc5,epcpc5,"research server",,,"Narnia Data Center",,,,, epcmsp,epcmsp,"Service Processor",,,"Narnia Data Center",,,,, post62a,post62a,"network printer",,netprinter,"Narnia Data Center",,,, +, tst401,"tst401, tst401.narnia.org, srv1ck41","Test Application Server" +,test,"linuxserver, nonprod, localperl, sudoers","Data Center, Narnia +",aslan,,sciops,DellR730,

The way forward always starts with a minimal test.

In reply to Re: Parsing ldap attributes into a csv by 1nickt
in thread Parsing ldap attributes into a csv by lvirden

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.