问题
Is there an option to find if my system is little endian byte order or big endian byte order using Perl?
回答1:
perl -MConfig -e 'print "$Config{byteorder}\n";'
See Perl documentation.
回答2:
I guess you could do:
$big_endian = pack("L", 1) eq pack("N", 1);
This might fail if your system has a nonstandard (neither big-endian nor little-endian) byte ordering (eg PDP-11).
来源:https://stackoverflow.com/questions/2610849/finding-if-the-system-is-little-endian-or-big-endian-with-perl