Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Reading input byte by byte

by leira (Monk)
on Apr 17, 2004 at 02:50 UTC ( [id://345928]=note: print w/replies, xml ) Need Help??


in reply to Reading input byte by byte

For some reason, it reads and prints the entire thing even though I only tell it to print 1 byte!

Actually, you're telling it to read one byte at at time, until there's nothing left (read returns the number of bytes it succeeded in reading -- when there are none left, it will return 0, and your while loop will stop):

while(read (TEST, $stuff, 1)) {

...and then you're appending what you read during this pass onto what you've already read, until $text contains everything in the file:

$text .= $stuff;

....and then you're printing out the whole thing:

print $text;

If you only want to read 1 byte and then stop, you probably don't want to put it in a while loop.

Linda

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-25 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found