O'Reilly logo

Learning Perl, Second Edition by Randal L. Schwartz, Tom Christiansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.6. <STDIN> as an Array

One previously seen operation that returns a different value in a list context is <STDIN> . As described earlier, <STDIN> returns the next line of input in a scalar context. However, in a list context, it returns all remaining lines up to end of file. Each line is returned as a separate element of the list. For example:

@a = <STDIN>; # read standard input in a list context

If the person running the program types three lines, then presses CTRL-D[4] (to indicate "end of file"), the array ends up with three elements. Each element will be a string that ends in a newline, corresponding to the three newline-terminated lines entered.

[4] Some systems use CTRL-Z to indicate end of file, while others use it to suspend a running process.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required