I am a beginner at perl.
I have no idea what while(<STDIN>)
is in the perl file.
What is it?
STDIN
is a file handle that is assigned to standard input.
What is standard input?
Inputs and pipes from the keyboard (for example, cat sample.txt||perl test.pl
) and
Redirected files (for example, perl test.pl<sample.txt
).
<STDIN>
is
<File Handle>
reads a line from the specified file and implicitly substitutes the variable $_
.
That is, read a line from the standard input and set the content to $_
.
while(<STDIN>)
is
Repeat until the condition fails in while
.
Repeat until the standard input is the last (EOF
is entered (Ctrl+Z for windows and Ctrl+D for UNIX series).
By the way
while(<STDIN>)
can omit STDIN
and write while(<>)
.(*If the command line argument does not contain more than one input file)
© 2024 OneMinuteCode. All rights reserved.