Another way to read input is with the diamond operator:
<>. This is useful for making programs that work like standard Unix utilities, with respect to the invocation arguments (which we’ll see in a moment). If you want to make a Perl program that can be used like the utilities cat, sed, awk, sort, grep, lpr, and many others, the diamond operator will be your friend. If you want to make anything else, the diamond operator probably won’t help.
The invocation arguments to a program are normally a number of “words” on the command line after the name of the program. In this case, they give the names of the files your program will process in sequence:
$ ./my_program fred barney betty
That command means to run the command
my_program (which will be found in the current directory), and that it should process file fred, followed by file barney, followed by file betty.
If you give no invocation arguments, the program should process the standard input stream. As a special case, if you give a hyphen as one of the arguments, that means standard input as well. If the invocation arguments had been
fred- betty, that would have meant that the program should process file fred, followed by the standard input stream, followed by file betty.
The benefit of making your programs work like this is that you may choose where the program gets its input at runtime; for example, you won’t have to rewrite the program to use it in a pipeline (which we’ll discuss ...