vios has asked for the wisdom of the Perl Monks concerning the following question:

I have got this strange results from a COM API return which use some type of Lists the strings in the TStrings object in system data format (SDF). property CommaText: string; Looks like this is standard Delphi format. However I am used with the nice and user friendly split format of Perl and not this dirty looks not friendly result. This is the source strings :

R50”R20 “Desc 4-10” R400,20 Test Test5””

This would be the result from the Delphi COM API

“R50””R20”,””Desc 4-10””,”R400,20”,Test,”Test5””””

So I need to reverse this back to the original strings. Anybody has some easy and good idea on how to do this.

Replies are listed 'Best First'.
Re: How to separate with double quote and comma.
by Tanktalus (Canon) on Nov 01, 2005 at 04:09 UTC

    Looks like pretty much standard CSV format to me. So I'd suggest Text::CSV, Text::xSV, Text::CSV_XS, or even DBD::CSV. Any one of them should do, although the last one will have vastly different syntax.

      Hello, I have tried using the function use Text::CSV and it looks not like it is that all standard CSV as this module will fail to parse the sample I have provided.

      C:\Documents and Settings\pietera\Desktop>perl csv.pl parse() failed on argument: R50""R20","""Desc 4-
Re: How to separate with double quote and comma.
by monarch (Priest) on Nov 01, 2005 at 06:14 UTC
    Seems to me that, before you process with a standard module, you need to eliminate instances of double-doublequotes.

    E.g.

    $i = '“R50””R20”,””Desc 4-10””,”R400,20”,Test,”Test5””””'; $i =~ s/\"{2}/*my_special_double_quote_marker*/g; ... normal double quote processing here ... foreach ( @cell ) { s/*my_special_double_quote_marker*/\"/g; }