I stopped using pipes, started using file handles, and things sped up nicely.<div><br></div><div>Thanks</div><div>Jay<br><br><div class="gmail_quote">On Wed, Apr 20, 2011 at 12:03 PM, Warren Lindsey <span dir="ltr"><<a href="mailto:warren.lindsey@gmail.com">warren.lindsey@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I assume by your use of <> and print without a filehandle that you are going through pipes and reading from STDIN and writing to STDOUT. I suspect opening input and output file handles will be more efficient. Less data movement between buffers.<br>


<br>
Cheers,<br>
Warren<br>
<div><div></div><div class="h5"><br>
On Apr 20, 2011, at 11:37 AM, Jay Strauss <<a href="mailto:me@heyjay.com">me@heyjay.com</a>> wrote:<br>
<br>
> Hi all,<br>
><br>
> 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:<br>


><br>
> use strict;<br>
><br>
> while(<>) {<br>
><br>
>       $_ = substr $_, 1, -2;  #       Remove first and last ", and remove<br>
>                               #       the \n at the same time<br>
>                               #<br>
><br>
>       s/\|/-/g;               #       Change embedded "|" into "-"<br>
><br>
>       my @words = split(/\",\"/,$_,-1);       # split on the remaining ","<br>
><br>
>       print join("|", @words),"\n";<br>
> }<br>
><br>
> 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.<br>
><br>
> I'm I doing something costly in the script above that is making it run so slow?<br>
><br>
> Thanks<br>
> Jay<br>
><br>
</div></div>> _______________________________________________<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>
_______________________________________________<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>