in reply to perl pack function

It does appear to me that that string got converted to UTF8. The question is: why? Did you append that string to some UTF8 string? In such a case, perl would "promote" the Latin-1 string to UTF8, with a result as you describe.

But perhaps this isn't really the contents of $msg. Perhaps it is only converted to UTF8 when you print it out to a file. In which case, perl thinks that's what you want. Perhaps tell it that the filehandle should be treated as raw, hence, no conversion of any characters? binmode could offer you a solution, then.

Replies are listed 'Best First'.
Re^2: perl pack function
by fvgestel (Initiate) on Oct 26, 2005 at 13:38 UTC
    I'm not printing to file; I'm filling a network-packet.
    here's a more complete snippet :

    my $msg = pack("C*",0x80,0x10,0x29, 0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x20, @data, 0x00,0x00,0x20,0x00,0x01,0xc0,0x0c,0x00,0x20, 0x00,0x01,0x00,0x04,0x93,0xe0,0x00,0x06,0x60, 0x00,@ip); my $len_msg = length($msg); my $num_short = $len_msg / 2; bind(S, $us); send(S, $msg, 0, $them) or die "send : $!"; my $res=''; recv(S,$res,0,0); close S;