$char =~ tr/ -~// and $input .= $char

The '-' indicates a range, from ' ' to '~', which if you look at a basic ASCII chart, is all the plain printable (visible and take up one character position) characters.

$char =~ tr/\b\x7f// is used because on my system the key labeled "Backspace" returns "\b" when running in xterm and "\x7f" when running on the Linux console. BTW, for your comment in the chatterbox, the \b in tr/\b\x7f// is an actual character "\x08" whereas the \b in a regex is a metacharacter and not an actual character.

The code implementing the backspace is wizardry :)
The idea is simple -> if you currently have N choices, find the longest initial substring that gives you more than N choices.
The wizardry is the the design of regex itself, credit Larry and the implementors...
The concept that regex finds the longest match is crucial in this program both for backspace and for advancing to the next decision point.


In reply to Re^6: [challenge] Nested autocompletion -- winner program unveiled to me by tybalt89
in thread [challenge] Nested autocompletion by Discipulus

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.