I'm not sure if this problem is actually a perl issue, but I will start here.

I am running code to capture user input, attempting to do some stuff with the cursor conditionally (using system calls to tput) depending on which character is entered, then printing out each character so it appears on the screen (as they would if echo were enabled.) All works fine if the user is typing input, the problem appears if the input is pasted into the terminal. I've isolated the problem to observe that it seems related to making a system call in the loop. All the pasted characters get printed out okay, until the system call is made, where the next character prints, but none following get printed. If I don't make the system call, all characters get printed fine.

I have also observed that it doesn't matter what system call I make (eg, ls or whatever), the same thing happens, so it is not just related to calling tput.

I've reduced the code to minimally demonstrate the issue. In this example, if text is pasted in, only the first character gets printed. If the system call in the loop is commented out, then all the text gets printed as expected. Also note that one character will print, regardless of whether the system call comes before or after the print call. Also note that it doesn't matter if I use system() or backtick notation.

#!/usr/bin/perl $| = 1; use strict; use warnings; system "stty -icanon -isig -echo min 1 time 0"; system "tput clear"; print "enter some text:\n"; processText(); sub processText { while ( my $char = STDIN->getc() ) { if (ord($char) == 3) { # Ctrl-C system "stty icanon echo isig"; exit; } # System call causes only a single character to print out, apparen +tly can # be anything, eg `ls`. Get same behavior with shell exec using ba +ckticks. system "tput sc"; print($char); } } system "stty icanon echo isig";

In reply to Pasting text when capturing user input only prints one character if system call is made in the loop by Allasso

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.