in reply to Binary conversion
#!/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.
|
|---|