Wednesday, April 08, 2009

Binary numerical file IO in PERL

#following is a simple example
open FP, '>a.bin';
binmode FP; #make it binary file
@values=(3.2,3.3,3.4); #list of floating values
$a=pack 'f3' , @values; #pack as 32bit floating point value
#use 'd' for 64bit floating point
syswrite(FP,$a,12); #save to file
close FP;