Finding if the system is little endian or big endian with perl

后端 未结 2 1386
無奈伤痛
無奈伤痛 2020-12-16 01:05

Is there an option to find if my system is little endian byte order or big endian byte order using Perl?

2条回答
  •  春和景丽
    2020-12-16 01:33

    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).

提交回复
热议问题