How can I convert floating point values in text to binary using Perl?

Posted by YoDar on Stack Overflow See other posts from Stack Overflow or by YoDar
Published on 2010-05-23T13:32:44Z Indexed on 2010/05/23 17:40 UTC
Read the original article Hit count: 189

Filed under:

I have text file looks like that:

float a[10] = {
7.100000e+000 ,
9.100000e+000 ,
2.100000e+000 ,
1.100000e+000 ,
8.200000e+000 ,
7.220000e+000 ,
7.220000e+000 ,
7.222000e+000 ,
1.120000e+000 ,
1.987600e+000
};
unsigned int col_ind[10] = {
1 ,
4 ,
3 ,
4 ,
5 ,
2 ,
3 ,
4 ,
1 ,
5
};

Now, I want to convert each array (float / unsigned int) to different binary files - big endian type. Binary file for all float values and binary file for all integer values.

What is the simple way to do it in Perl, consider I have over 2 millon elements in each array?

© Stack Overflow or respective owner

Related posts about perl