Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delimiter character inside the fields

13 views
Skip to first unread message

George.Perl

unread,
Jun 18, 2009, 5:50:55 PM6/18/09
to
I have incoming files from an external source where the delimiter character
very often is inside the fields. Look at the following example

$line = 'f1 , f2, "hello , world" , "nice , try" ';

$line =~s|"([^"]*?)"|{$_=$^N;tr','.';$_}|gse;
print scalar (split /\s*,\s*/,$line,-1);

So I use this regex to change the invalid commas to dots, but I am looking
something more generic. Any Ideas ?

Jim Gibson

unread,
Jun 18, 2009, 6:51:33 PM6/18/09
to
In article <h1ecrs$cu6$1...@mouse.otenet.gr>, George.Perl
<nospam.gr...@hotmail.com.nospam> wrote:

There are modules available from CPAN to handle this sort of input.
See, for example, Text::CSV.

--
Jim Gibson

Gunnar Hjalmarsson

unread,
Jun 18, 2009, 6:58:08 PM6/18/09
to

Yes, as the applicable FAQ entry says.

perldoc -q delimited

> See, for example, Text::CSV.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

0 new messages