How to prompt a user for input in Perl

Home > Search > How-to
  by

The following markup can be used to produce a prompt for user input in Perl.

#!/usr/bin/perl

print "Enter your name: ";
my $name = <STDIN>;
chomp $name;

print "Your name is $name";

 

Here is an example of running this script.

~]# ./example.pl
Enter your name: Jeremy
Your name is Jeremy

 



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




Comments