Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: 20 years confused

by kcott (Archbishop)
on Jun 13, 2020 at 05:35 UTC ( [id://11118011]=note: print w/replies, xml ) Need Help??


in reply to 20 years confused

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

Replies are listed 'Best First'.
Re^2: 20 years confused
by jcb (Parson) on Jun 14, 2020 at 03:04 UTC

    That is a good catch — select-and-paste trimmed the trailing whitespace on my system and I did not notice the "odd space out" in the sample output.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-18 02:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found