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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ok, here's a strange one!

Status
Not open for further replies.

LenLindquist

IS-IT--Management
Oct 17, 2002
31
0
0
US
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 &quot;%lx&quot;, 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top