FreeKB - Perl Prompt a user for input
Perl - 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. 

#!/usr/bin/perl

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 e3cd7 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |