पहली बार पोस्टर और अंशकालिक perl noobie।पर्ल में इनपुट कैसे रोकें?
मैं एक रिफ्लेक्स गेम बना रहा हूं। यहाँ उत्पादन है -
__________________________________________________________________________
Reflex game initiated. Press ENTER to begin the game, and then press ENTER
after the asterisks are printed to measure your reflexes!.
*************************
Your result: 0.285606 seconds.
logout
[Process completed]
__________________________________________________________________________
नहीं है एक छोटी सी समस्या है, हालांकि - वहाँ 0-10 सेकंड (एक यादृच्छिक चर के आधार पर) के बाद आप खेल शुरू करने के लिए और सितारों मुद्रित कर रहे हैं इससे पहले कि दबाएं। उस समय, यदि खिलाड़ी ENTER दबाता है, तो यह उनके रिफ्लेक्स समय के रूप में लॉग होता है। इसलिए सितारों को मुद्रित करने से पहले मुझे अपने कोड को अपने एंटर बटन पढ़ने से रोकने का एक तरीका चाहिए। कोड -
#!/usr/bin/perl
use Time::HiRes qw(sleep);
use Time::HiRes qw(gettimeofday);
#random delay variable
$random_number = rand();
print "Reflex game initiated. Press ENTER to begin the game, and then press ENTER after the asterisks are printed to measure your reflexes!.\n";
#begin button
$begin = <>;
#waits x milliseconds
sleep(10*$random_number);
#pre-game
$start = [ Time::HiRes::gettimeofday() ];
print "\n****************************\n";
#user presses enter
$stop = <>;
#post game
$elapsed = Time::HiRes::tv_interval($start);
#delay time print
print "Your result: ".$elapsed." seconds.\n";
सितारों ने आउटपुट में प्रिंट नहीं किया, इसके बारे में खेद है। वे 'आपके प्रतिबिंब:' और 'आपके प्रतिबिंबों को मापने के लिए मुद्रित' के बीच में सही हैं। – user1472747
[फ्लशिंग पर्ल एसटीडीआईएन बफर] के संभावित डुप्लिकेट (http://stackoverflow.com/questions/7602861/flushing-perl-stdin-buffer) – pilcrow