[ale] One for the perl hackers

Erik Mathis erik at mathists.com
Fri Oct 4 10:19:11 EDT 2013


Even if you escape the comma, its still goin to slip in the comma.

I'd just remove the comma, or change it to something else.

#!/usr/bin/perl -w
use Data::Dumper;
$String='component1,component2,"This is my, test string", component4';
print $String,"\n";
$String =~  s|"(.+),(.+)"|$1$2|;
print $String,"\n";
print Dumper split(',', $String);

emathis at emathis-lappy:~$ perl /tmp/123.pl
component1,component2,"This is my, test string", component4
component1,component2,This is my test string, component4
$VAR1 = 'component1';
$VAR2 = 'component2';
$VAR3 = 'This is my test string';
$VAR4 = ' component4';



On Thu, Oct 3, 2013 at 6:08 PM, Jim Kinney <jim.kinney at gmail.com> wrote:

> Unless you have a magical way to escape the comma inside the quoted
> string, you're stuck. sed 's/\(".\+\),\(.\+"\)/\1\\,\2/g' file. Assuming
> all intermediate strings will be double quoted.
>
> Might try splitting to an array instead of individual string vars. Then
> you can do a length test to see if you got something "extra".
> @strings = split(',' , $String);
>
> Be sure to empty the array after each run or loop it as a local variable
> created each pass.
>
>
>
> On Thu, Oct 3, 2013 at 5:22 PM, Robert L. Harris <
> robert.l.harris at gmail.com> wrote:
>
>>
>> *Sorry for the OT but my only perl lists have gone dark a long time ago*
>>
>>
>> $String='component1,component2,"This is my, test string", component4';
>>
>> ($C1, $C2, $Str, $C4) = split(',', $String);
>>
>> I'm only getting "This is my" in $Str and $C4 does not contain
>> "component4".  Is there a graceful way of handling this?  It's a 1 in 10000
>> chance it'll break but accuracy counts.
>>
>> Robert
>>
>>
>> --
>> :wq!
>>
>> ---------------------------------------------------------------------------
>> Robert L. Harris
>>
>> DISCLAIMER:
>>       These are MY OPINIONS             With Dreams To Be A King,
>>        ALONE.  I speak for                      First One Should Be A Man
>>        no-one else.                                     - Manowar
>>
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>>
>>
>
>
> --
> --
> James P. Kinney III
> *
> *Every time you stop a school, you will have to build a jail. What you
> gain at one end you lose at the other. It's like feeding a dog on his own
> tail. It won't fatten the dog.
> - Speech 11/23/1900 Mark Twain
> *
> http://heretothereideas.blogspot.com/
> *
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20131004/bb2a7792/attachment.html>


More information about the Ale mailing list