Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8824561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:39:52+00:00 2026-06-14T06:39:52+00:00

When I type after Enter a string: for example a , b , c

  • 0

When I type after Enter a string: for example a, b, c and then two times Ctrl+D I get an endless loop which doesn’t halt on ReadKey and which I can not stop with the Q key?

#!/usr/bin/env perl
use warnings;
use 5.10.1;
use Term::ReadKey;

while( 1 ) {
    my $c;
    say "Press the \"q\" key to quit.";
    print "Press the \"e\" key to enter a string: ";
    {
        $|++;
        Term::ReadKey::ReadMode 'ultra-raw';
        $c = ReadKey 0;
        Term::ReadKey::ReadMode 'restore';        
    }
    exit if ord( $c ) == 3; # Control C
    last if $c eq 'q'; 
    if ( $c eq 'e' ) {
        print "\nEnter a string: ";
        my $string = <>;
        if ( not defined $string ) {
            say "Undefined";
        }
        else {
            chomp $string;
            say "You entered |$string|";
        }
    }
    say "Still running";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:39:54+00:00Added an answer on June 14, 2026 at 6:39 am

    After you type the two Ctrl–D (EOT), your programm will only receive NUL-bytes. And an infinity of them. Unfortunately you have an unconditional read in an infinite loop. Either you change that (e.g. give the user a lesson if he types something other than q or e and exit if he didn’t get it after the third try), or you implement control characters correctly. Your module strips all control characters from the input before you even get it, but it provides the neccessary hooks. I urge you to add Ctrl–C as well (it only works when a line is expected, not when a char is being read).

    Also, why not compare the input characters with string equality? $c eq "q" reads nicer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would be possibile to get the original data type after applying the ArrayToStringTransformer to
I have bug with UIImagePickerController which source type is camera. Sometimes after controller appeared,
I got this url /search/renttype-all.place-all.type-all.bedrooms-all.0.0/ I want to get the text after the second
Here is my problem. Immediately after I type in some input and hit enter
After defining the following : abstract class A { type T def print(p: T)
After doing some experimentation with move semantics with an array type I created, I
I try to implement an initialization method for my own type. However after calling
I've upgraded Resharper from 5 version to 6 version. After that when I type
I try to get input from a textfield of type INPUT and save its
i need to validate this type of string 0415256987, 0452 654 987, 0411 236589,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.