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

Re^2: ztk-webcam snapshot-grabber

by PhillipHuang (Beadle)
on Jul 20, 2011 at 09:38 UTC ( #915618=note: print w/replies, xml ) Need Help??


in reply to Re: ztk-webcam snapshot-grabber
in thread ztk-webcam snapshot-grabber

Would you explain what "$|++" meaning is in the code? Thanks

Replies are listed 'Best First'.
Re^3: ztk-webcam snapshot-grabber
by Anonymous Monk on Jul 21, 2011 at 02:29 UTC
Re^3: ztk-webcam snapshot-grabber
by Anonymous Monk on Jul 21, 2011 at 02:25 UTC

    Would you explain what "$|++" meaning is in the code? Thanks

    Its like $foo++ except working on the variable $| , a reall shell-ish (or hack-ish) way to turn autoflush on, as in

    use IO::Handle; print 1; # doesn't print, puts 1 in the buffer STDOUT->autoflush(1) print 1; # prints 1 immediately (and the previously buffered 1) print "\n2\n"; # \n forces a flush
    Tutorials: Input and Output: Suffering from Buffering?

        Just think me as a kid. When i run the below script, it really print 1(not as your comment).

        Well, that is not my code ;) buffering means printing doesn't happen immediately, it is delayed, barring a crash of some sort, it will happen eventually, like when a program exits, when all buffers are flushed .

        Try this instead

        use IO::Handle; print "\n2\n"; # \n forces a flush, 2 printed immediately print 1; # doesn't print, puts 1 in the buffer sleep 1; # still nothing printed STDOUT->autoflush(1); # buffered 1 printed print "\n"; # prints immediately sleep 1; print 1; # prints 1 immediately sleep 1; print "\n";

        Without sleep, you wouldn't notice the buffering, and without sleep, I forget to add sleep or test my original code:) but its ok since I linked to the tutorial for you to read, and run its code, and believe what it says is true :) because it is :) I did, I did taw a puddy tat

        Anonymous Tweety Pie

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-08-11 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?