G'day OrdinaryFIlmmaker,

Welcome to the Monastery.

It would've helped if you'd read "How do I post a question effectively?" before posting. Providing your data as paragraph (<p>) text does not allow us to see what it really is: HTML will, amongst other things, convert sequences of whitespace to a single space. We might have got clues from your code, but you didn't post that.

Here's what your input data looked like (newlines are represented by '$'s):

$ cat -vet pm_11118005_data Eli Stern,,, $ 10-Nov-19,,, $ 1 subscriber,,, $ ,,, $ Abdessamed Ham,,, $ 15-Nov-19,,, $ 0 subscribers,,, $ ,,, $ Arne Martinson,,, $ 22-Nov-19,,, $ 0 subscribers,,, $ ,,, $

Your wanted output is also questionable: space before 1st date but not the others; and, records ending with 2 commas, a space, and a newline.

Except for the dodgy space before the 1st date, this code produces the output you asked for:

#!/usr/bin/env perl use strict; use warnings; use autodie; { open my $fh, '<', 'pm_11118005_data'; local $/ = "\n,,, \n"; while (<$fh>) { chomp; print join(',', $., split(/,,, \n?/)), ",, \n"; } }

Output:

1,Eli Stern,10-Nov-19,1 subscriber,, 2,Abdessamed Ham,15-Nov-19,0 subscribers,, 3,Arne Martinson,22-Nov-19,0 subscribers,,

Update: A very minor update (adding a single missed letter) which changes the meaning (to what I originally intended).
Was: "I would've helped if ..."
Now: "It would've helped if ..."

— Ken


In reply to Re: 20 years confused by kcott
in thread 20 years confused by OrdinaryFIlmmaker

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.