lichtjiang
Programmer
For example, say we want to write integer "100" in a binary file, "test.dat". The following code won't work.
$anumber=100;
$file="test.dat";
open(DAT, ">", $file);
print DAT $anumber;
This will write 3 bytes in "test.dat" as 31, 30, and 30. Though, if $anumber is read as "64" in hex from a binary file, then "64" can be written to "test.dat" in 1 byte.
It seems a scalar variable only writes its string value to disk file. Why? Any idea how to write a number's native value into a binary disk file? Thanks!
$anumber=100;
$file="test.dat";
open(DAT, ">", $file);
print DAT $anumber;
This will write 3 bytes in "test.dat" as 31, 30, and 30. Though, if $anumber is read as "64" in hex from a binary file, then "64" can be written to "test.dat" in 1 byte.
It seems a scalar variable only writes its string value to disk file. Why? Any idea how to write a number's native value into a binary disk file? Thanks!