Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to read floating point number from a file

Status
Not open for further replies.

xavoton

Programmer
Dec 19, 2000
1
MX
hi, im trying to read a database file from a specific non comercial software. I already decoded the parts I need. There are some double precision float numbers that I want to read. I used:

read(FILE,$number,8);

since I supposed the perl doubles are 64bit long.
The point is that when I print the variable $number, perl treats it like a string instead of as a number. Does any body knows a trick to do this? or I should use C++ or another more powerful language in low level operations.

Thank you for your help

Xavier Maurer
 
Check out perl's

prompt> perldoc -f unpack

to see how to read a file that is a binary file, this may help you. Otherwise, I think you're reading 8 ascii characters, which is not what you want to do. You want to read the bytes as a nubmer, whcih unpack lets you specify.

As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
I would argue that Perl is more powerful than C++. Also, if you prefer to use C code, then you can do so directly in your Perl script... it passes it to your compiler. Check the perldocs.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top