Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: string and sysread and read work differently

by seattlejohn (Deacon)
on Dec 24, 2002 at 00:29 UTC ( #222001=note: print w/replies, xml ) Need Help??


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!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://222001]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2023-02-06 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (34 votes). Check out past polls.

    Notices?