Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

3. Lists and Arrays > <STDIN> in List Context

<STDIN> in List Context

One previously seen operator that returns a different value in an array context is the line-input operator, <STDIN>. As we described earlier, <STDIN> returns the next line of input in a scalar context. Now, in list context, this operator returns all of the remaining lines up to the end-of-file. It returns each line as a separate element of the list. For example:

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

When the input is coming from a file, this will read the rest of the file. But how can there be an end-of-file when the input comes from the keyboard? On Unix and similar systems, including Linux and Mac OS X, you’ll normally type a Control-D[92] to indicate to the system that there’s no more input; the special character itself is never seen by Perl,[93] even though it may be echoed to the screen. On DOS/Windows systems, use Ctrl-Z instead.[94] You’ll need to check the documentation for your system or ask your local expert if it’s different from these.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial