Perl | Use of STDIN for Input Last Updated : 18 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Perl allows the programmer to accept input from the user to perform operations on. This makes it easier for the user to give input of its own and not only the one provided as Hardcoded input by the programmer. This Input can then be processed and printed with the use of print() function. Input to a Perl program can be given by keyboard with the use of <STDIN>. Here, STDIN stands for Standard Input. Though there is no need to put STDIN in between the 'diamond' or 'spaceship' operator i.e, <>. It is standard practice to do so. <> operator can be used to write to files as well. <STDIN> can be also be used in Scalar and List context. Syntax: $x = <STDIN>; or $x = <>; Example: Perl #!/usr/bin/perl -w use strict; use warnings; print"Enter some text:"; my $string = <STDIN>; print "You entered $string as a String"; Input: GeeksForGeeks Output: Enter some text: GeeksForGeeks You Entered GeeksForGeeks as a String In the above code, after giving Input, there is a need to press ENTER. This ENTER is used to tell the compiler to execute the next line of the code. But, <STDIN> takes this ENTER key pressed as a part of the Input given and hence when we print the line. A new line will automatically be printed after the Input string. To avoid this, a function chomp() is used. This function will remove the newline character added to the end of the Input provided by the user. Example: Perl #!/usr/bin/perl -w use strict; use warnings; print"Enter some text:"; my $string = <STDIN>; chomp $string; print "You entered $string as a String"; Input: GeeksForGeeks Output: Enter some text: GeeksForGeeks You Entered GeeksForGeeks as a StringTaking Input using just <> - Without using STDIN or stdin we can take user input just by using <>. Perl #!/usr/bin/perl print("Please enter your age : "); $age = <>; print("Your age is $age"); Comment More infoAdvertise with us Next Article Perl | Use of STDIN for Input A Abhinav96 Follow Improve Article Tags : Perl Perl-Input-Output Similar Reads Perl | STDIN in Scalar and List Context STDIN in Perl is used to take input from the keyboard unless its work has been redefined by the user. Syntax: <STDIN> or <> STDIN in Scalar Context  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 t 3 min read Perl | Writing to a File A filehandle is a variable that is used to read and write to a file. This filehandle gets associated with the file. In order to write to the file, it is opened in write mode as shown below: open (FH, â>â, âfilename.txtâ); If the file is existing then it truncates the old content of file with the 3 min read Perl | File I/O Functions File handling in Perl is used to read data from an external file or to write data into an external file. This is very useful as it provides a platform to permanently store and retrieve data from files. File Handle A FileHandle associates a name to an external file, that can be used until the end of 4 min read Perl | getc Function getc() function in Perl is used to read the next character from the file whose File Handle is passed to it as argument. If no FileHandle is passed then it takes one character as input from the user. Syntax: getc(FileHandle) Parameter: FileHandle: of the file to be read Returns: the character read fr 1 min read Take input from stdin in Python In this article, we will read How to take input from stdin in Python. There are a number of ways in which we can take input from stdin in Python. sys.stdininput()fileinput.input()Read Input From stdin in Python using sys.stdin First we need to import sys module. sys.stdin can be used to get input fr 2 min read Like