Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Input on a per-character basis?

WeirdofreakWeirdofreak Posts: 439Member
Is there a way of getting input from STDIN so that every character is grabbed and evaluated individually? It's no big deal if it isn't, or if the solution is overly complex, but I'd like to avoid the redundant enter-presses if feasible, and since the sort of input is going to be based on the first character typed, getting that character before they press return is the only problem I can think of.

Comments

  • XfactorXfactor Posts: 343Member
    : Is there a way of getting input from STDIN so that every character is grabbed and evaluated individually? It's no big deal if it isn't, or if the solution is overly complex, but I'd like to avoid the redundant enter-presses if feasible, and since the sort of input is going to be based on the first character typed, getting that character before they press return is the only problem I can think of.

    The only thing I can think of is to split the STDIN input. Something like:

    @chars = split(//, );

    Now the last character will have the newline but you can chomp it off.

    X
  • JonathanJonathan Posts: 2,914Member
    : Is there a way of getting input from STDIN so that every character is grabbed and evaluated individually? It's no big deal if it isn't, or if the solution is overly complex, but I'd like to avoid the redundant enter-presses if feasible, and since the sort of input is going to be based on the first character typed, getting that character before they press return is the only problem I can think of.
    :
    You can probably use the read function, using STDIN as the file handle. Give the length you want to read as 1 to read an individual character.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • WeirdofreakWeirdofreak Posts: 439Member
    Unfortunately that requires a linebreak (or carriage return, or whatever) before it reads. It did however lead me on the trail to a POSIX solution which seems my best bet, but I don't know if that'll work in Win/DOS (if not, I'll probably just check $^O). There's also the Term::ReadKey module, but that's nonstandard so anybody who wants to run it (assuming anybody -will- want to run it of course) will face dependancy errors, which I don't like. I'm also not entirely sure it doesn't need the linebreak (that's what I'm assuming a non-blocking read means) and it apparantly also had problems with Windows.
Sign In or Register to comment.