Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
string and sysread and read work differentlyby gary kuipers (Beadle) |
on Dec 23, 2002 at 23:34 UTC ( [id://221997]=perlquestion: print w/replies, xml ) | Need Help?? |
gary kuipers has asked for the wisdom of the Perl Monks concerning the following question:
I need to read a file at a starting position ( != 0) and keep reading until I encounter a "\n" (ordinal 10), then stop. I am using sysopen, sysseek and sysread. The characters I am fetching are just fine (they display properly). The problem comes in when I try to determine the ordinal value of the just-read character ($c): sysread(RCVQ,$c,1,$ptr); my $x = ord($c); print "$c=$x\n"; yields T=0 (zero). Actually all characters are = ordinal 0, which is clearly wrong. ord() will provide the correct ordinal number if I say ord('E') or $c = 'E'; ord($c). So it is not ord() that is broken. per dox, ord() returns the ordinal value of the first character of the string it is passed. Does Perl infer that $c is a character and pass a 2 or more byte string (unicode??) to ord() ???
Back to
Seekers of Perl Wisdom
|
|