user input in perl?

Please tell me how to write a perl script that asks the user to enter words and that passes them to a variable.

In bash, the "read" command would achieve such user interaction.

#!/bin/bash
read -p "Enter files: " vFiles

However, I am looking for perl version of something equivalent to bash's "read".

Many thanks in advance.

You read input from stdin by using the special STDIN file descriptor.

print "Type something and hit enter: ";
$LINE=<STDIN>;
1 Like

Corona688's answer is pretty right, but don't forget to chomp!
chomp removes the newline character from the end of line.

chomp($LINE);

the line input operator includes the newline at the
end of the input. There are lots of ways to remove that newline, but
the best way is to use the "chomp" function
source: [Courses] [Perl] Part 3: User Input and "chomp"

1 Like