FreeKB - Perl (Scripting) Prompt a user for input
Perl (Scripting) - Prompt a user for input

Let's say you want to prompt a user for input, like this.

What is your name?


The following markup can be used to produce the prompt. 


print "What is your name? \n";
my $name = <STDIN>;


In this example, whatever the user types at the prompt will be stored in a variable named $name. The $name variable can be printed to display the users name.

print "Your name is $name \n";


The $name variable may contain new lines, thus it's good practice to use chomp to remove new lines.

chomp $name;


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter f46de in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |