in reply to Re: zero fill with pack
in thread zero fill with pack

Ikegami, The 'NN' "fake-out" worked nicely. Two things though, I also need to pad the above value with two spaces, i.e., "00 00 00 00 00 09 fe 00 20 20" - need a total byte displacement of ten: how can I pad/add two more spaces at the end of my value? And, what is the significance of the ", 0," in the "pack('NN', 0, $_)" statement? Again, thanks for your prompt response!

Replies are listed 'Best First'.
Re^3: zero fill with pack
by ikegami (Patriarch) on Jun 22, 2010 at 18:34 UTC

    what is the significance of the ", 0," in the "pack('NN', 0, $_)" statement?

    The value for the first "N".

    Q=654848 ----------------------- 00 00 00 00 00 09 fe 00 ----------- ----------- N=0 N=654848

    I also need to pad the above value with two spaces, i.e., "00 00 00 00 00 09 fe 00 20 20"

    More concisely, you want to add two spaces. pack:

    C An unsigned char (octet) value. A A text (ASCII) string, will be space padded.
    pack('NN CC', 0, $_, ord(' '), ord(' ')) pack('NN CC', 0, $_, 0x20, 0x20) pack('NN A2', 0, $_, ' ') pack('NN n', 0, $_, 0x2020)
      AWESOME ikegami - Thanks!!
      ikegami - I found out I need to be able to handle one or two bytes worth of data adding nine or eight spaces: e.g., 00 20 20 20 20 20 20 20 20 20 or 00 00 20 20 20 20 20 20 20 20 Is there something smaller than an unsigned short (16bit)? I'm trying to figure out the correct pack template to use for the above examples.
        ikegami - I think I figured it out for myself using the "i" and "n" templates....