this code is 100% untested, but i think it might do something like what you want. i wish i had more time now, but i'll have to leave it to others to comment if you don't understand. sorry again to dump and run, but i hope this helps.

Update: okay, i found a couple minutes to comment the code and test the script. i've updated the code to a working version, and provided sample input and output. let me know if you have any trouble with this. if the comments aren't enough help, we'll be happy to explain what's going on.

#!/usr/bin/perl use strict; use warnings; use 5.006; $|++; require Text::CSV; ## for writing a proper CSV file ## get arguments from the commandline my( $infile, $outfile )= @_; ## set the template for unpacking the database ## see 'perldoc -f pack' for details my $template= 'A30A30A40'; ## verify arguments or display usage 2 == @ARGV or die "usage: db2csv infile outfile\n"; ## open the files, $infile for reading, $outfile for writing ## see 'perldoc perlopentut' for details open local(*IN) => '<', $infile or die 'infile:', $!; open local(*OUT) => '>', $outfile or die 'outfile:', $!; ## create a CSV object my $csv= Text::CSV->new(); ## set the input record seperator to 100 bytes ## see 'perldoc perlvar' for details local $/= \100; ## process infile a line at a time while( <IN> ) { ## unpack the database record ## and create a csv record $csv->combine( unpack $template => $_ ) or die "cannot create record $.:", $csv->error_input() || $!; ## print the string to the output file print OUT $csv->string(), "\n"; } __END__ sample input: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCC +CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCddddddddddddddddddddddddddddddeeeeeeeee +eeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffffff sample output: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB","CCC +CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" "dddddddddddddddddddddddddddddd","eeeeeeeeeeeeeeeeeeeeeeeeeeeeee","fff +fffffffffffffffffffffffffffffffffffff"

~Particle *accelerates*


In reply to Re: What's the most efficient way to write out many lines of data? by particle
in thread What's the most efficient way to write out many lines of data? by Anonymous Monk

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.