While this obviously lends itself to a CSV module, wouldn't it be considerably simpler just to use split?

my @lines; while (<FILE>) { my @fields = (split /,/, $line)[1,2,3,4,5,9,11,12,13,15,16,17,18,1 +9,20,21,22,23,24]; for (0..$#fields) { $fields[$_] = qq("$fields[$_]") unless /^"[^"]*"$/; } push @lines, @fields; }

Lastly, verify your column numbers -- I passed your input line through `cut -d, -f1,2,3,4,5,9,11,12,13,15,16,17,18,19,20,21,22,23,24` and I don't seem to recall seeing the address, even after adjusting the index by removing Map,:

Axxxx,F,Bxxxx,BXXXX Axxxx,000000,NOTE:XXXXX Xxxxx (000000)@EX%SMTP:xxxxx.xxxxx@xx.com%X400:c=CA;a=;p=XX;o=xxxxxxxxxxxxx;s=XXXXX;g=Xxxxx;,Customer Srv Centre,WORKS/ SRV,SUPPORT/ SUPPORT, + 0000,(000) 000-0000 +,(000) 000-000,,,666 Snowball Paves,Vancouver,ON,CAN,J7G 3Y4

I ran another for verification:

Waaaaaa,,Lbbbbbbbb,Lccccccc Wddddddddddd,555555,SMTP:eeeeeee.fffffff@gggg.tld%HHHHHHH Iiiiiii@EX%X400:c=JJ;a=;p=KK;o=LL;s=Mmmmmm;g=Nnnnn;,Maint,,M STAT,5555,,,,,,,,,

UPDATE: Evidently the OP has a binary input file with escaped (or otherwise present) delimiters, but did not indicate which of these delimiters are escaped in the sample input.

Lastly, if it really is a binary file, don't forget to use binmode.

UPDATE: Given Corion's decision to remove any potentially personally identifiable information (a decision which I support), the above will need to be changed to reflect the new sample input... done.

During the anonymization I discovered that while coping the OP's sample input I accidentally mangled the first one -- the first `cut` output has been updated to reflect this. While the second was not mangled, it has lost context with the removal of the additional sample lines.

Nevertheless, the problem remains that the OP was using the incorrect column specification.

UPDATE: Changed the for loop from the OP's implementation to actually maintain the quoted values.


In reply to Re: parsing a field by eibwen
in thread parsing a field by hotpower

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.