It is not clear how you are getting your data but if you hold the column names in a separate array from the data you can use List::MoreUtils->mesh() to combine the two, joining each element with the delimiter \x01.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -MList::MoreUtils +=mesh -E ' my $delim = qq{\x01}; my @colHdrs = qw{ Name Sex Age Job }; my @data = ( [ qw{ Fred M 27 Janitor } ], [ qw{ Mary F 31 Researcher } ], ); my $outFile = q{spw11101656.out}; open my $outFH, q{>}, $outFile or die qq{open: > $outFile: $!\n}; foreach my $raDataLine ( @data ) { say $outFH join $delim, mesh @colHdrs, @{ $raDataLine }; } close $outFH or die qq{close: > $outFile: $!\n};' johngg@shiraz:~/perl/Monks$ hexdump -C spw11101656.out 00000000 4e 61 6d 65 01 46 72 65 64 01 53 65 78 01 4d 01 |Name.Fred +.Sex.M.| 00000010 41 67 65 01 32 37 01 4a 6f 62 01 4a 61 6e 69 74 |Age.27.Jo +b.Janit| 00000020 6f 72 0a 4e 61 6d 65 01 4d 61 72 79 01 53 65 78 |or.Name.M +ary.Sex| 00000030 01 46 01 41 67 65 01 33 31 01 4a 6f 62 01 52 65 |.F.Age.31 +.Job.Re| 00000040 73 65 61 72 63 68 65 72 0a |searcher. +| 00000049

I hope this is helpful.

Cheers,

JohnGG


In reply to Re: Creating data delimited by ASCII code 1 using perl by johngg
in thread Creating data delimited by ASCII code 1 using perl by dasun

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.