getc is supposed to return a char. I find that it doesn't return the correct value for non-printable characters. For example:
open(FILE, $ARGV[$1]) || die("can't open: $!"
;
$namlen=getc(FILE);
$len=read(FILE,$fname,$namlen);
The first byte contains the length of the string that follows. In my test file its value is hex 0B. But $namlen is 0, not 11.
read(FILE,$namlen,1); doesn't work any better
In the final line of my example, I can change $namlen to a constant value of 11 and the string is read just fine.
In C, reading a byte value would be trivial. What is the trick to make it work in Perl?
open(FILE, $ARGV[$1]) || die("can't open: $!"
$namlen=getc(FILE);
$len=read(FILE,$fname,$namlen);
The first byte contains the length of the string that follows. In my test file its value is hex 0B. But $namlen is 0, not 11.
read(FILE,$namlen,1); doesn't work any better
In the final line of my example, I can change $namlen to a constant value of 11 and the string is read just fine.
In C, reading a byte value would be trivial. What is the trick to make it work in Perl?