The reason the middle one:
$float = unpack "f", pack "N", unpack "V", $data;
feels wrong is probably because it is wrong. You have a network-order value that you need to convert to host-order value; I'll explain this backwards, as that's how perl has to process it.
unpack "V", $data;
This treats the data as if it were in Little-endian order (which is it is not) and turns it into a 32-bit integer.
pack "N", $data;
This packs the data into a string in Big-endian (network) order. This is also wrong, because you now are using it on a little-endian machine.

This is one of those few cases where two wrongs *do* make a right; these operations are done in the wrong order, but the net effect is the same (which is why it works).

Your last suggestion,

pack 'L', unpack 'N', $data
is the most correct version. The unpack('N') unpacks the number as if it were a 32-bit value in network byte order (which it is), and the pack('L') re-packs the number as a 32-bit value in host byte order (which it is).

In reply to Re: Network IEEE 754 to Native Floats: which pack/unpack ops better? by Stevie-O
in thread Network IEEE 754 to Native Floats: which pack/unpack ops better? by shenme

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.