On Fri, 04 Mar 2005 17:36:50 -0700, Peter Bowen <[EMAIL PROTECTED]> wrote: > I suggested it because this is what pack/unpack was designed to do... > extract data from streams. In this case a null terminated string.
Seems to me a trivial usage of pack, and not as clear to follow up programmers. I'd automatically look for more than was there. Plus, he didn't say he wanted to get rid of *all* nulls, just at the end of the string. You're example would strip the nulls. I'd be curious to see what kind of benchmarks we'd see ... hmmm. The regex is about 25% faster than the unpack. See http://beta.harleypig.com/benchmark/bench_regex_or_unpack.txt for my logic and http://beta.harleypig.com/benchmark/bench_regex_or_unpack_results.txt for the results. > I've seen code where this is done with substrs to try to chop off the junk > at the beginning and lop off the terminator at the end - because the > programmer didn't realize that the "junk" was a couple of ints to describe > the type of message, and the length of the text, and the null was the string That's not a problem with using the regex, that's a problem with programmer education. > to expect. By unpacking and handling the data, we converted it to an event > driven model that can Tivo radio in perl... it was pretty cool - it still is Sounds like it. Don't suppose you've made that code public? -- Alan .===================================. | This has been a P.L.U.G. mailing. | | Don't Fear the Penguin. | | IRC: #utah at irc.freenode.net | `==================================='
