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';

  • Comment on Re: string and sysread and read work differently

Replies are listed 'Best First'.
Re: Re: string and sysread and read work differently
by gary kuipers (Beadle) on Dec 24, 2002 at 01:18 UTC
    DOH!

    I am using the OFFSET $ptr as an offset in the file I am reading instead of what it really is ... an offset into the string I am placing the data into.

    ARRRGH! Too tired!

    Thanks for your help!!!