Posted by Frank Hale on 2001-01-13
Assuming I have the following code which reads a text file in called
test.txt which only has the words "Hello,World!" in it. This code gets the
file size and puts each byte of the file into an array. I want to print off
each byte as a hexidecimal number. I cannot get printf to do it. What am I
doing wrong?
BEGIN {
my @file_bytes;
# open a file for reading
open(INFILE, "test.txt") or die("Error: unable to open file");
$file_size = (stat("test.txt"))[7];
for ($a = 0; $a < $file_size; $a++)
{
sysread(INFILE, $byte, $a);
push @file_bytes,$byte;
$byte=0;
}
foreach $byte (@file_bytes)
{
printf ("%x ", $byte);
}
}
--
ICQ: 7205161
http://sapphire.sourceforge.net/ - A small window manager for X11
http://javathingies.sourceforge.net/ - My java junk
"The box said it requires Windows 95 or better so I installed Linux"
Previous post | Next post | Timeline | Home