I have a file where each row is 1 record with about 65 columns of information. I need to test some of these columns for specific ranges of values. So I naturally want to use split like this:
my (@Cols) = split (",", $lRow);
Here is the problem: many of the rows have free-text comment blocks with commas that are delimited by double-quotes like this:
1123,,,"10.11.12.13",4,"I really, really wanted",,,"It was, like great
+"
1123,,,"34.123.12.12",8,"Fantastic",,,"",,
How do I remove all commas if they are between ," and ", bracketing pairs?
Note: I dont have to preserve the free-text comments. Is there a regrex to detect & replace everything between: ," and ", if there is a comma with ,"",? The problem is: things like IP addresses and email address are also enclosed in " characters and I need to preserve them. Another problem, some people put multiple comma's in their comments like: "It was ,,,,, the worst experience of my life"
Note: I can make multiple passes through the row so I have thought about replacing all ," combinations with ,| combinations and all ", combinations with |, then replacing everything between two || chars with "".
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.