in reply to Use pack to create a float in non-native format

perldoc -f pack says

All integer and floating point formats as well as p and P and () -groups may be followed by the > or < modifiers to force big- or little- endian byte-order, respectively. This is especially useful, since n , N , v and V don't cover signed integers, 64-bit integers and floating point values. However, there are some things to keep in mind.
but take note of
Forcing big- or little-endian byte-order on floating point values for data exchange can only work if all platforms are using the same binary representation (e.g. IEEE floating point format). Even if all platforms are using IEEE, there may be subtle differences. Being able to use > or < on floating point values can be very useful, but also very dangerous if you don't know exactly what you're doing. It is definitely not a general way to portably store floating point values.

  • Comment on Re: Use pack to create a float in non-native format

Replies are listed 'Best First'.
Re^2: Use pack to create a float in non-native format
by mjscott2702 (Pilgrim) on Feb 07, 2010 at 10:04 UTC
    That was what I needed (teach me to read the manpages all the way down). Since the binary structure I am creating contains a field specifying the endianess of the data, simply doing something like

    print pack 'f>', 1.2345;

    worked like a charm. Thanks to all for the responses.