Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to use quotewords for CSV text, but still make it not ignore the trailing empty fields?

Reply
Thread Tools

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

 
 
mmasroorali@cse.buet.ac.bd
Guest
Posts: n/a
 
      05-02-2005
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,

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      05-02-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in
news:(E-Mail Removed) ups.com:

> 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:umper;

use Text:arseWords;

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
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
 
 
 
Damian James
Guest
Posts: n/a
 
      05-04-2005
On 1 May 2005 20:15:19 -0700, (E-Mail Removed) said:
> 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


--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@{$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
XSD to allow A-Z 0-9 and spaces, but not leading/trailing spaces johkar XML 2 12-10-2009 09:24 AM
Re: How to trim a String trailing spaces, but not leading spaces? Roedy Green Java 3 09-14-2008 02:10 AM
Re: How to trim a String trailing spaces, but not leading spaces? John B. Matthews Java 4 09-12-2008 05:28 AM
Trailing empty space added when using Repeater and DataReader Andrei Pociu ASP .Net 4 10-14-2004 06:16 PM



Advertisments