in reply to Binary conversion


Here is a small example that writes some packed 4-byte floats to a file and then re-reads them. See $/ in perlvar and pack, unpack and read in perlfunc.
#!/usr/bin/perl -w use strict; my @floats = (1, 2.34, 5.6e8, .001); # Write the floats to a file open BINFILE, ">msfile" or die "Error message here: $!\n"; binmode BINFILE; # Required on Windows print BINFILE pack "f*", @floats; close BINFILE; # Open the file for reading open BINFILE, "msfile" or die "Error message here: $!\n"; { # Read the file in 4 byte chunks local $/ = \4; while ((<BINFILE>)) { # Unpack the floats print unpack("f", $_), "\n"; } }

Update: If the endianess of the machines are different modify the unpack as follows:     print unpack("f", reverse $_), "\n";

--
John.