I was hoping there's a clever way to work with parameters in pack() itself, which would change it's behavior to pad left side
Not sure that it can be classified as "clever", but if you "scalar reverse()" twice, it seems to produce the correct result (for your given example, at least) :
print scalar reverse unpack "H*", pack("H*", scalar reverse "a12");
Cheers, Rob | [reply] [d/l] |
however I was hoping there's a clever way to work with parameters in pack() itself As far as I can tell, there isn't one. Though I agree that would have been interesting.
this is meant to be in a CPAN package I wanted to keep it as clean as possible
I suppose that's why you don't want to put the function in its own file? Because it kind of belongs in a separate module?
Why do it even pad numbers on the right side?
Because adding things on the right of your data should not change how the left part is interpreted, I guess
I just thought of another way to do what you want: pack 'H*', 'a12' =~ s/^(.(..)*)$/0$1/rxs. Still not as clear as a function though.
| [reply] [d/l] |