- while (<>) {
-
chomp;
-
print "It was $_ that I saw!\n";
-
}
diamond operator will automatically open and close a series of files for you, or read from the standard-input stream if there aren’t any filenames given.
with the argument file "test.txt", "a.txt", "b.txt". it will ouput all lines of the three files. without break. the current file name stored in
$ARGV.
If you find yourself
putting two diamonds into the same program, especially using the second diamond
inside the while loop that is reading from the first one, it’s almost certainly not going
to do what you would like.* In our experience, when beginners put a second diamond
into a program, they meant to use $_ instead.
Remember, the diamond operator
reads the input, but the input itself is (generally, by default) found in $_.
the diamond operator reads from @ARGV. so we can force the @ARGV to change the files.
阅读(450) | 评论(0) | 转发(0) |