in reply to use encoding affects pack()
I don't think the behaviour of pack (here) is affected by the encoding pragma. "n" means an unsigned short in network order, which is unrelated to strings (except that pack returns a string).
However, the encoding pragma does affect how the returned string is printed. From perldoc encoding we know:
The encoding pragma also modifies the filehandle layers of STDIN and STDOUT to the specified encoding.
So, if you want to stick to the utf8 encoding pragma but don't want to output this string in utf8:
perl -Mencoding=utf8 -e 'binmode STDOUT, ":bytes" or die $!; print(pack("n", 204))'
or
perl -e 'use encoding "utf8", STDOUT => undef; print(pack("n", 204))'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: use encoding affects pack()
by rasher (Acolyte) on Aug 10, 2008 at 00:41 UTC |