ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
6. Basic I/O6.1 Input from STDINReading from standard input (via the Perl filehandle called $a = <STDIN>; # read the next line
Evaluating in a list context produces all remaining lines as a list: each element is one line, including its terminating newline. We've seen this before, but as a refresher, it might look something like this: @a = <STDIN>; Typically, one thing you want to do is read all lines one at a time and do something with each line. One common way to do this is: while (defined($line = <STDIN>)) { # process $line here } As long as a line has been read in, Reading a scalar value from while (<STDIN>) { # like "while(defined($_ = <STDIN>)) {" chomp; # like "chomp($_)" # other operations with $_ here } Since the |