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

I want to assign the value say: 'ABC' 0x01 0x02 0x00 0x00 0x00 0x09 to a nine byte string. I assume I can get there, but question one is what is the best (most efficient) way to do that?

Question two is why doesn't this work?
my $var = pack('a3CCx3C','ABC',01,02,09);
That produces:
Illegal octal digit '9' at ./myscript line 10, at end of line
I can change 09 to 19 or 99, then it will "work" (meaning it assigns that value, which isn't the value that I want). What is wrong with 09?

Replies are listed 'Best First'.
Re: Assigning a hexadecimal string
by FunkyMonk (Bishop) on Jan 01, 2010 at 12:02 UTC
    Numbers with a leading 0 aren't interpreted as decimal. '0x' is used for hex, '0b' for binary and '0' for octal.

    See Scalar value constructors in perldata for details.