I was under the impression that regexs were slow.<div><br></div><div>I changed to your suggestion.  I think the real prob was using pipes </div><div><br></div><div>Thank you</div><div>Jay<br><br><div class="gmail_quote">On Wed, Apr 20, 2011 at 11:49 AM, tiger peng <span dir="ltr"><<a href="mailto:tigerpeng2001@yahoo.com">tigerpeng2001@yahoo.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div style="font-family:Courier New,courier,monaco,monospace,sans-serif;font-size:10pt">why split and join? try replace '","' with '|' directly.<br>

<div><br></div><div style="font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><br><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><font face="Tahoma" size="2"><hr size="1">

<b><span style="font-weight:bold">From:</span></b> Jay Strauss <<a href="mailto:me@heyjay.com" target="_blank">me@heyjay.com</a>><br><b><span style="font-weight:bold">To:</span></b> Chicago.pm chatter <<a href="mailto:chicago-talk@pm.org" target="_blank">chicago-talk@pm.org</a>><br>

<b><span style="font-weight:bold">Sent:</span></b> Wed, April 20, 2011 11:37:47 AM<br><b><span style="font-weight:bold">Subject:</span></b> [Chicago-talk] Performance issue<br></font><div><div></div><div class="h5"><br>Hi all,<div>

<br></div><div>I have a csv file, with quoted strings (i.e. "field1","field2",...).  The file is 3.5M
 records.  I'm running strawberry perl on win7 (not that I think that's the issue).  What I need to do is convert any embedded "|" to "-", convert the field delimiter ' "," ' to "|".  I know there are cpan mods for parsing csv but my situation is pretty straight forward.  I'm doing:</div>



<div><br></div><div><div>use strict;</div><div><br></div><div>while(<>) {</div><div><br></div><div><span style="white-space:pre-wrap">  </span>$_ = substr $_, 1, -2; <span style="white-space:pre-wrap"> </span>#<span style="white-space:pre-wrap">       </span>Remove first and last ", and remove</div>



<div><span style="white-space:pre-wrap">  </span>                        #<span style="white-space:pre-wrap">       </span>the \n at the same time</div><div><span style="white-space:pre-wrap">                          </span>#</div>

<div><br></div><div><span style="white-space:pre-wrap"> </span>s/\|/-/g;<span style="white-space:pre-wrap">       </span>        # <span style="white-space:pre-wrap">      </span>Change embedded "|" into "-"</div>



<div><br></div><div><span style="white-space:pre-wrap"> </span>my @words = split(/\",\"/,$_,-1);<span style="white-space:pre-wrap">     </span># split on the remaining ","</div>

<div><br></div><div><span style="white-space:pre-wrap"> </span>print join("|", @words),"\n";</div><div>}</div></div><div><br></div><div>But it's take what seems like a long time to run (like 15 mins).  I'd think this would be an ideal use for Perl, and could rip through the file lickedy split.</div>



<div><br></div><div>I'm I doing something costly in the script above that is making it run so slow?</div><div><br></div><div>Thanks</div><div>Jay</div><div><br></div>
</div></div></div></div>



</div></div><br>_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br></blockquote></div><br></div>