Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Delimiter character inside the fields
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
George.Perl  
View profile  
 More options Jun 18 2009, 5:50 pm
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Gibson  
View profile  
 More options Jun 18 2009, 6:51 pm
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gunnar Hjalmarsson  
View profile  
 More options Jun 18 2009, 6:58 pm
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

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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »