Here is a simple example using Term::ReadKey. The script prompts for a name and reads the input character by character (as they are entered) until a newline is found or the input reaches 15 characters:
use strict; use warnings; use Term::ReadKey; $!++; print "Enter name: "; my $key; my $name = ""; my $count = 0; ReadMode 4; while ($count < 15){ while (!defined ($key = ReadKey(-1))){ # Waiting for key pressed } last if ($key eq "\n"); print $key; $name .= $key; $count++; } ReadMode 0; # do whatever you want with your input, for example, print it: print "\n$name\n";
citromatik
In reply to Re^4: restriction in input
by citromatik
in thread restriction in input
by irah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |