There's also the procedure in Mastering Regular Expressions:
(lifted from The Perl Cookbook)

[CODE FOLLOWS]
sub parse_csv{
        my $text = shift; #record containing comma sep values
        my @new = ();
        push(@new, $+) while $text =~ m{
                #the first part groups the phase inside the quotes.
                #see explanation of this pattern in MRE
                "([^\"\\]*(?:\\.[^\"\\]*)*)",?
                        | ([^,]+)+),?
                        | ,
                }gx;
                push (@new, undef) if substr($text, -1,1) eq ',';
                return @new;   #list of values that were comma separated.
[END OF CODE]
The assumption is the text based fields are enclosed in quotes (like your
example)


-----Original Message-----
From: Filip Sneppe (Yucom) [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 24, 2001 12:42 PM
To: [EMAIL PROTECTED]
Subject: Cleanest way to split this


Hi,

I have input lines that look like this:

  username,[EMAIL PROTECTED],age,streetname number zip-code
city,www.website.com/user/default.html

and that need to be split into $username, $email, etc.

Easy to do, but some of the records look like this:

  username,[EMAIL PROTECTED],18,"streetname 54B, 1000 Brussels",www.site.com
  "Doe, John",[EMAIL PROTECTED],40,"blah blah,,, ,stuff",www.site2.org

What would be the easiest way to take into account the quotes when splitting
?

TIA,
Filip


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to