I am trying to build a script that will parse a file that people filled out for more information about a clients product.

Some of these people put like numbers like, 5,000 and 1,000 and they are comma delimited fields, thus that entry will throw off the rest of them. Usually when they are delivered to me those fields are all surrounded by "".

So I did this:
$_lfile = param("lfile"); # Get the contents via copy n paste $_lfile2 = $_lfile; # Make a temp variable ($_line1,$lfile2) = split /\015\012/, $_lfile2, 2; # Split by line bre +aks in windows format while($_line1 =~ /\"/) { # Check if this line contains quote ($_line1,$_extraLine1) = split /\"/, $_line1, 2;# Split by Quote if($_extraLine1 =~ /\"/) {#If contains another then spolit again ($_extraLine1,$_extraLine2) = split /\"/, $_extraLine1, 2; }# End the check to see if contained another quote. $_extraLine1 =~ s/\,/g;#Now strip out the comma's in the field bet +ween the quotes. $_line1 = "$_line1$_extraLine1$_extraLine2";# Now replace the line + contents, without the quotes and extra comma's }# End while statement
Now I get this error:

syntax error at /home/path_to_files/pages/file_parser.conf line 29, near "while(($__field,$_line1) = split /\" Compilation failed in require at index.cgi line 39.

That is the code just under the above. If I comment the above code out then there are no errors in that part of the code, it works just fine. Can I not do a contains "=~" looking for a quote? I tried it escaped and not escaped, same result.

Thanks for any wisdom...

thx,
Richard

In reply to Checking if line contains a quote by powerhouse

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.