sprintf convert each value in turn, only for perl ops to stick them together, I use x to replicate the per-byte format string once for each byte I'm about to convert. There's now one "\\xX" for each of the numbers in the list passed from unpack to sprintf, so sprintf just does what it's told. And sprintf is faster than perl ops.pack, unpack and sprintf. So why not use them? All the pack and unpack code is implemented in pure C, so doesn't have any of the book-keeping overhead of perl ops. sprintf too is pure C, so it's fast. The regexp engine uses its own private bytecode, but it's specially tuned for regexps, so it runs much faster than general perl code. And the implementation of tr has less to do than the regexp engine, so it's faster.
For maximum power, remember that you can generate regexps and the formats for pack, unpack and sprintf at run time, based on your data.
$&, use (?:...) when you don't need capturing, and put the /o flag on constant regexps.
评论加载中…
![]() |