David,<br><br>The split function is not going to make things any faster. In fact, without resorting to the use of another language, I can&#39;t think of a faster way of doing it than you have suggested. Even if you were to split on something like a quote followed by a space (/&quot; /) and then reattach the quote to the end of each resulting element (work that is vastly simpler than regex matching), the process would end up being slower than regex matching because the regex maching happens in machine language and the more efficient work happens in Perl. I&#39;m convinced also that even if you were to use the index function, your Perl code would still be slower than the regex-based solution you described.<br>
<br>In the past, I have tried a number of tricks to try to beat simple regex matching for this type of work and I&#39;ve seldom been able to beat the regex matching. (When I write &quot;this type of work&quot;, I am of course excluding regular Apache-like log files and other files that are designed to be easy and fast to parse. I&#39;m talking about more thoughtless file designs, such as the one you described.) <br>
<br>You could roll out your own C extension, but that&#39;s just ridiculous because the hardware to process the slower and more general Perl regex would be less expensive than your time. <br><br>I don&#39;t know how you timed the split function, but I suspect that it was much faster because its regex was probably much simpler. If you try the split function with a more complicated regex, I&#39;m sure you&#39;ll find that split isn&#39;t so fast any more. <br>
<br>You do need the /g at the end, of course.<br><br>--Donnie<br><br><br><div class="gmail_quote">On Mon, Oct 27, 2008 at 5:27 PM, B. Estrade <span dir="ltr">&lt;<a href="mailto:estrabd@mailcan.com">estrabd@mailcan.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">David,<br>
<br>
Maybe the following will help:<br>
<br>
<a href="http://oreilly.com/catalog/perlwsmng/chapter/ch08.html" target="_blank">http://oreilly.com/catalog/perlwsmng/chapter/ch08.html</a><br>
<br>
I don&#39;t know a whole bunch about parsing tons of text with regexes. I do have one immediate suggestion - that &quot;/g&quot; might not be necessary. Anyway, take a look at that link; it might help.<br>
<br>
Cheers,<br>
Brett<br>
<div><div></div><div class="Wj3C7c"><br>
On Mon, Oct 27, 2008 at 03:59:32PM -0500, David B. John wrote:<br>
&gt; (perl v5.8.8 on Ubuntu Hardy Heron/2.6.24-21-generic.)<br>
&gt;<br>
&gt; I have an http logfile I&#39;m trying to parse which looks like:<br>
&gt;<br>
&gt; 2008:10:24-00:00:06 x.x.x.x httpproxy[4997]: id=&quot;0001&quot; severity=&quot;info&quot;<br>
&gt; sys=&quot;SecureWeb&quot; sub=&quot;http&quot; name=&quot;http access&quot; action=&quot;pass&quot; method=&quot;GET&quot;<br>
&gt; srcip=&quot;x.x.x.x&quot; user=&quot;&quot; statuscode=&quot;200&quot; cached=&quot;0&quot; profile=&quot;profile_0&quot;<br>
&gt; filteraction=&quot;action_REF_DefaultHTTPCFFAction&quot; size=&quot;78632&quot; time=&quot;105<br>
&gt; ms&quot; request=&quot;0x90075b60&quot;<br>
&gt; url=&quot;<a href="http://sb.google.com/safebrowsing/update?client=navclient-auto-ffox&amp;appver=2.0.0.17&amp;version=goog-white-domain:1:481,goog-white-url:1:371,goog-black-url:1:25401,goog-black-enchash:1:62374" target="_blank">http://sb.google.com/safebrowsing/update?client=navclient-auto-ffox&amp;appver=2.0.0.17&amp;version=goog-white-domain:1:481,goog-white-url:1:371,goog-black-url:1:25401,goog-black-enchash:1:62374</a>&quot; error=&quot;&quot; category=&quot;175,178&quot; categoryname=&quot;Software/Hardware,Internet Services&quot; content-type=&quot;text/html&quot;<br>

&gt;<br>
&gt;<br>
&gt; (Nothing Spectacular.)<br>
&gt;<br>
&gt; If I loop through the log file and do:<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; my ($date,$fwip,$proxy,$id,$severity,$sys,$sub,$name,$action,$method,<br>
&gt; $srcip,$user,$statuscode,$cached,$profile,$filteraction,$size,$time,<br>
&gt; $request,$url,$error,$category,$category_name,$content_type) =<br>
&gt; $_ =~ /\w+=&quot;.*?&quot;|\S+/g;<br>
&gt;<br>
&gt; life is good but could be better (~ 75 seconds on a Hp dc7700S for a<br>
&gt; compressed 500 MB logfile).<br>
&gt;<br>
&gt; However, I&#39;d really like to use split b/c it&#39;s so much faster (~ 15<br>
&gt; seconds). &nbsp;The problem is if I split, sometimes $name, $time or<br>
&gt; $category_name will include a space within the quotes which I don&#39;t want<br>
&gt; to split on (see above).<br>
&gt;<br>
&gt; I used Text::ParseWords but gave up after waiting 5 minutes.<br>
&gt;<br>
&gt; I know I can use a regex with split but I&#39;m stumped as to how I would go<br>
&gt; about writing it. &nbsp;E.g. split on a space except when enclosed in quotes.<br>
&gt; Also, would it theoretically be any faster than the example above since<br>
&gt; it&#39;s using regex or should I just live with it?<br>
&gt;<br>
&gt; Thanks.<br>
&gt;<br>
&gt; David<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; NewOrleans-pm mailing list<br>
&gt; <a href="mailto:NewOrleans-pm@pm.org">NewOrleans-pm@pm.org</a><br>
&gt; <a href="http://mail.pm.org/mailman/listinfo/neworleans-pm" target="_blank">http://mail.pm.org/mailman/listinfo/neworleans-pm</a><br>
<br>
</div></div><font color="#888888">--<br>
B. Estrade<br>
Louisiana Optical Network Initiative<br>
+1.225.578.1920 aim: bz743<br>
:wq<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<br>
NewOrleans-pm mailing list<br>
<a href="mailto:NewOrleans-pm@pm.org">NewOrleans-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/neworleans-pm" target="_blank">http://mail.pm.org/mailman/listinfo/neworleans-pm</a><br>
</div></div></blockquote></div><br>