Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I find very often the need to pack spaces on the left or pack with zeroes. I have used the following code so much I will probably work it into a personal library.

I, being a mere acolyte of Perl, wonder if anyone has another (better?) way to do this. Or perhaps someone has a way to streamline this approach.

sub myrpack ($$) { my($template, $charstring) = @_; $charstring = reverse $charstring; $charstring = pack $template, $charstring; $charstring = reverse $charstring; return $charstring; }

Even though you can pass in a template for the pack, I have only ever had the need for A. Another limit in this routine that has yet to bother me is you can only introduce one string for packing. You can't pack several together.

I have had the need to pack with more than one string because I've wanted to pack 0's onto a number, much like an odometer. I just pack a6a*, $zeroes, $numstring where $zeroes is just a string of zeroes longer than any of my fields. In each of these cases, I have to figure the 6 somewhere (length of field - length of $numstring).

-T