http://qs1969.pair.com?node_id=222001


in reply to string and sysread and read work differently

Is $ptr zero when you call sysread? What happens if you omit $ptr from the call?

If $ptr is nonzero, sysread is going to insert the characters into $c someplace other than the beginning of the string. I would suspect that $c gets filled from the left with chr(0) if needed, which is why ord then returns 0.

If you wanted to reliably get the ordinal of the string you just read, I think you'd need to use something like my $x = ord(substr($c,$ptr,1));. Or get rid of $ptr (or make sure it's really 0) so you are actually reading into the beginning of $c.

        $perlmonks{seattlejohn} = 'John Clyman';