STDIN in Perl is used to take input from the keyboard unless its work has been redefined by the user.
In order to take input from the keyboard or operator is used in Perl. This operator reads a line entered through the keyboard along with the newline character corresponding to the ENTER we press after input.
So $age contains the input given by the user as well as the new line character. In order to remove the new line, chomp function is used which removes “\n” from the end of the string.
When STDIN is used with list context, it takes multiple values as an input from the keyboard. Press ENTER to indicate individual elements in the list. In order to indicate the ending of inputs, press Ctrl-D in Linux systems whereas Ctrl-Z in Windows system.
The example below shows the use of STDIN in list context.
Here is how the above program works:
Step 1: Get List input from the user separated by ENTER.
Step 2: When Ctrl-D is pressed it indicates the ending of inputs, so, Perl assigns everything to the @city array.
Step 3: Use chomp function to remove new line from all the inputs.
Step 4: Printing the city names given as in input.
- Perl | Hash in Scalar and List Context
- Perl | Scalar Context Sensitivity
- Perl | Use of STDIN for Input
- Perl | scalar keyword
- Perl | List Context Sensitivity
- Perl | Basic Syntax of a Perl Program
- Perl Tutorial - Learn Perl With Examples
- jQuery | context Property
- Perl List and its Types
- Perl | List Functions
- Perl Installation and Environment Setup in Windows, Linux, and MacOS
- Perl | Removing leading and trailing white spaces (trim)
- Perl | undef and the defined function
- Perl | Variables and its Types
- Perl | Constructors and Destructors
- Perl | Finding Files and Directories
- Perl | Opening and Reading a File
- Perl | Quoted, Interpolated and Escaped Strings
- Perl | Number and its Types
- Perl | Mutable and Immutable parameters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.