Yes, of course, I agree. If execution time is
really critical, then I can easily believe that
pack is faster, I have observed that myself quite a few times. But if execution time is not so crucial, then I would say that the time you spend writing relatively complicated subroutines using
pack and
unpack might not be worth the effort. An hour of a developer's working time is worth many many many CPU cycles. But this is of course your decision, based on your knowledge of the process.
Writing the examples above using printf took me probably about 5 to 6 minutes, perhaps even less, I know that using pack will probably take me hours, because the syntax is quite complicated (or perhaps because I don't master it well enough, but that does not really change the net result). Being an independent consultant, I know what my time is worth, and I know that I will go for the smaller developer's time consuming option, except if high performance is really badly needed.
Oh, and BTW,the solution I offered seems to work also with negative integers.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.