[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



    
[...]


    Greg> I was so impressed with Perl and Fletch that it could do
    Greg> this in a single line.

    Greg> I don't speak Perl at all, so I did not realize he was only
    Greg> scanning 1K blocks and any patterns that crossed the
    Greg> boundary were ignored.  (I assume that is the issue you
    Greg> found.)

Hey, pay no attention to that match split across buffer boundaries. :)


That of course was the quick and dirty one-liner that catches most
cases.  (Yeah, that's the ticket . . .)  To really do it right you
want to append into a buffer and search that buffer each time, then
clear all but the last (patternlength-1) characters from your buffer
before the next iteration.


That'd look something akin to:

$ perl -le 'print "a" x 2047, "\xff" x 16, "b" x 512' > foo
$ perl -lne 'BEGIN{$/=\1024}$o=($.-1)*1024-length$b;$b.=$_;print "hit byte ", $o + $-[0] if $b =~ /\xff{16}/;$b=substr($b,-15,15)' foo
hit byte 2047
$ perl -le 'print "a" x 2040, "\xff" x 16, "b" x 512' > foo
$ perl -lne 'BEGIN{$/=\1024}$o=($.-1)*1024-length$b;$b.=$_;print "hit byte ", $o + $-[0] if $b =~ /\xff{16}/;$b=substr($b,-15,15)' foo
hit byte 2040


Of course genericising this (and dealing with figuring out the longest
possible length string that an arbitrary regex could match) is left as
an exercise for the reader . . . :)

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U


</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00765" href="msg00765.html">[ale] Binary Grep</a></strong>
<ul><li><em>From:</em> jkinney at localnetsolutions.com (James P. Kinney III)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00753" href="msg00753.html">[ale] Binary Grep</a></strong>
<ul><li><em>From:</em> joe at madewell.com (Joe Steele)</li></ul></li>
<li><strong><a name="00756" href="msg00756.html">[ale] Binary Grep</a></strong>
<ul><li><em>From:</em> greg.freemyer at gmail.com (Greg Freemyer)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00756.html">[ale] Binary Grep</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00758.html">[ale] problems with Cendyne 32x10x40 USB CD-RW with SUSE 9.2 and	FC3</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00756.html">[ale] Binary Grep</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00765.html">[ale] Binary Grep</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00757"><strong>Date</strong></a></li>
<li><a href="threads.html#00757"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>