Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Creating data delimited by ASCII code 1 using perl

by johngg (Canon)
on Jun 21, 2019 at 09:47 UTC ( #11101662=note: print w/replies, xml ) Need Help??


in reply to Creating data delimited by ASCII code 1 using perl

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11101662]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2020-05-26 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (150 votes). Check out past polls.

    Notices?