What does while (<STDIN>) mean in perl?

Asked 1 years ago, Updated 1 years ago, 76 views

I am a beginner at perl.
I have no idea what while(<STDIN>) is in the perl file.
What is it?

perl

2022-09-30 18:46

1 Answers

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)


2022-09-30 18:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.