Generating valid CSV records is more trivial than parsing CSV records. In this case, all of your data are character strings, not numbers or timestamps, so it's appropriate to quote all three fields all the time.
"Jacobs, April","750.467.9582","quam.quis@sedhendrerit.org"
"Mays, Martena","870.348.1974","sollicitudin@nonummyFusce.org"
"McNeil, Brennan","289.527.6151","lobortis@nisl.com"
"Sexton, Melvin ""The Copymeister""","599.927.5337","in.felis@vari
+us.com"
"Blackburn, Prescott","661.589.1228","sed@egetlaoreetposuere.edu"
The most important thing to anticipate when generating CSV records in which every field is quoted is the possibility of the presence of the quote character in the data. The most common convention nowadays for escaping literal occurrences of the quote character is to use the same character as an escape character ("").
for (@client_values) {
s/(?=")/"/g;
s/^/"/;
s/$/"/;
}
my $client_record = join ',', @client_values;
Don't print the record piecemeal, one field at a time. Doing this is a worst practice, IMHO. Instead, generate a valid, whole CSV record and then print it.
print "$client_record\n";
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.