I'm having a trouble formatting a file into a pipe delimited set of records.

The record file (file.txt) looks like this:

0211121253 Mike Dell ID06533 0211121253 Chris Jones ID02014 0211121253 Pa Kettle ID65255 0111119112 Mitch Poo ID05983

I'm trying to read the file in to a handle and put a pipe ("|") at the beginning of each line. Then replace the spaces in each line with a pipe and then add a pipe to the. So, I would end up with a text file end of each line. It should resemble the following:

|0211121253|Mike|Dell|ID06533| |0211121253|Chris|Jones|ID02014| |0211121253|Pa|Kettle|ID65255| |0111119112|Mitch|Poo|ID05983|

Here's part of my code. I'm using the DBI module to query the original data from Oracle. I believe my error is because I'm working with an array and not string vars.

I would appriciate some advice on how this could be done.

$sth->execute; open (OUTFILE, "> file.txt") or die "Cant open dat file : $!"; while (@row = $sth->fetchrow_array) { $_ =~ s/\s/\|/g; print OUTFILE "@row\n"; } close OUTFILE;
Thanks, Neurotoxx

In reply to parse array to replace specific spaces with pipes by neurotoxx

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.