Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: sysread and null characters

by ggg (Scribe)
on Mar 24, 2005 at 17:18 UTC ( [id://442125]=note: print w/replies, xml ) Need Help??


in reply to Re^3: sysread and null characters
in thread sysread and null characters

Congratulations on Sainthood, Tanktalus!

Your explanation of sysread clarifies some other puzzeling behaviors I was seeing but didn't mention. Thanks!

I've bookmarked your links to regex info - your explaination gave me a cross between Do'h and deja vu.

One more thing, if you don't mind. The sysread info on perldoc.perl.org says Use sysread() and check for a return value for 0 to decide whether you're done. I'd like to use that feature to end the while loop rather than incrementing a counter, but is that return value zero? If so, how would I tell the difference from a zero in the data?

Or is that talking about some test value the function itself returns? ($EndTest = systead( FH, $a, $b ))

ggg

Replies are listed 'Best First'.
Re^5: sysread and null characters
by Tanktalus (Canon) on Mar 24, 2005 at 18:10 UTC

    The idea is that sysread is not returning the data, but a simple code that says "success" or "failure". The data is stored in your buffer ($digit).

    my $i; while (sysread FH, $digit, 1) # same as: while (sysread(FH, $digit, 1) != 0) # (well, not quite, but close enough here.) { ++$i; # keep track of which digit we're looking at. # deal with the $digit you just got. printf "%04d %d\n", $i, $digit; }

      Thank you, Tanktalus! I really appreciate your time on this. It surprises me how much was left out of the perldoc description of this function.

      Again, thanks!

      ggg

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-25 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found