LenLindquist
IS-IT--Management
I am reading a file one byte at a time, converting each byte using a translation table, and then writing a new file. This exercise isn't my primary concern, however.
I have a file with the following bytes:
41 42 43 1A 45
(the beginning of the alphabet, with a control character replacing "D"
When I read each byte, everything goes along merrily until the "1A" character is read. I am displaying ord($byte) for each character read, and all the other characters (including some other control characters I tried) seem to work great. The 1Ah however, is read in as 00h.
Here is the complete program:
$file="testfile.txt";
open (INFILE,$file);
open (DEBUG,">debug.txt"
;
$size=(stat($file))[7]; $byte=0;
while ($byte <= $size)
{
seek(INFILE,$byte,0);
read(INFILE,$inbyte,1);
print ord($inbyte);
$inhex=sprintf "%lx", ord($inbyte);
$byte++;
}
close DEBUG; close INFILE;
I guess my question is, does ord() process some control characters in an unusual way? And, is there an alternative to reading a file a byte at a time without losing any of the information the file contains? I.e., avoid the 1Ah problem.
I am using ActiveState ActivePERL. Any help you can offer is appreciated.
Len
I have a file with the following bytes:
41 42 43 1A 45
(the beginning of the alphabet, with a control character replacing "D"
When I read each byte, everything goes along merrily until the "1A" character is read. I am displaying ord($byte) for each character read, and all the other characters (including some other control characters I tried) seem to work great. The 1Ah however, is read in as 00h.
Here is the complete program:
$file="testfile.txt";
open (INFILE,$file);
open (DEBUG,">debug.txt"
$size=(stat($file))[7]; $byte=0;
while ($byte <= $size)
{
seek(INFILE,$byte,0);
read(INFILE,$inbyte,1);
print ord($inbyte);
$inhex=sprintf "%lx", ord($inbyte);
$byte++;
}
close DEBUG; close INFILE;
I guess my question is, does ord() process some control characters in an unusual way? And, is there an alternative to reading a file a byte at a time without losing any of the information the file contains? I.e., avoid the 1Ah problem.
I am using ActiveState ActivePERL. Any help you can offer is appreciated.
Len