Input from Files with while Loops and <>

Over the last three days, you've seen a number of examples that read input from the keyboard using <STDIN>. You've also used the standard input file handle in both a scalar and list context, so at this point you should know the difference between input in a scalar context (line by line) and input in a list context (read until end-of-file).

Getting input from the keyboard, however, is pretty tedious for any amount of input more than a few lines. That statistics script we worked on yesterday proves it—entering more than a couple of numbers into the script takes a long time, and if we want to just add to the existing data, we have to reenter it all each time.

Ideally, then, we'd store the data in a separate ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.