Delimiter character inside the fields
The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: alt.perl
From:
"George.Perl" <nospam.gravital... @hotmail.com.nospam>
Date: Fri, 19 Jun 2009 00:50:55 +0300
Local: Thurs, Jun 18 2009 5:50 pm
Subject: Delimiter character inside the fields
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 ?
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: alt.perl
From:
Jim Gibson <jimsgib... @gmail.com>
Date: Thu, 18 Jun 2009 15:51:33 -0700
Local: Thurs, Jun 18 2009 6:51 pm
Subject: Re: Delimiter character inside the fields
In article <h1ecrs$cu
... @mouse.otenet.gr>, George.Perl
<nospam.gravital
... @hotmail.com.nospam> wrote:
> 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 ?
There are modules available from CPAN to handle this sort of input.
See, for example, Text::CSV.
-- Jim Gibson
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: alt.perl
From:
Gunnar Hjalmarsson <nore... @gunnar.cc>
Date: Fri, 19 Jun 2009 00:58:08 +0200
Local: Thurs, Jun 18 2009 6:58 pm
Subject: Re: Delimiter character inside the fields
Jim Gibson wrote:
> In article <h1ecrs$cu
... @mouse.otenet.gr>, George.Perl
> <nospam.gravital
... @hotmail.com.nospam> wrote:
>> 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 ?
> There are modules available from CPAN to handle this sort of input.
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
You must
Sign in before you can post messages.
You do not have the permission required to post.