How to use quotewords for CSV text, but still make it not ignore the trailing empty fields?

M

mmasroorali

Dear All,
I have some autogenrated CSV text where a typical line looks like this,

"A", "B, C and D", "E",,,,,

See the empty fields at the end? Now when I use quotewords, the
trailing null fields are stripped from the result. So, I get only three
fields. But I want to get the last columns as empty fields. In case of
split, I could use the limit as the third parameter. Could any kind
soul please tell me what I could do in this situation?

Regards,
 
A

A. Sinan Unur

(e-mail address removed) wrote in
Dear All,
I have some autogenrated CSV text where a typical line looks like
this,

"A", "B, C and D", "E",,,,,

See the empty fields at the end? Now when I use quotewords, the
trailing null fields are stripped from the result.

Please read the posting guidelines for this group. Please always post a
minimal example that exhibits the problem you want to solve.
So, I get only three fields.

How so?

use strict;
use warnings;

use Data::Dumper;

use Text::parseWords;

my @fields = quotewords(',\s*', 0, q{"A", "B, C and D", "E",,,,,});
print Dumper \@fields;

__END__

C:\Home> c.pl

$VAR1 = [
'A',
'B, C and D',
'E',
'',
'',
'',
'',
undef
];

I don't know why the last field is undef rather than ''.

Sinan
 
D

Damian James

Dear All,
I have some autogenrated CSV text where a typical line looks like this,

"A", "B, C and D", "E",,,,,

See the empty fields at the end? Now when I use quotewords, the
trailing null fields are stripped from the result. So, I get only three
fields. But I want to get the last columns as empty fields. In case of
split, I could use the limit as the third parameter. Could any kind
soul please tell me what I could do in this situation?

Quotewords? You don't mean as in 'qw'? Don't see how that applies.

Use Text::CSV. Really, there are more issues that dealing with additional
commas. You don't want to revisit them all.

--damian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,086
Latest member
ChelseaAmi

Latest Threads

Top