I am not getting "<>" diamond operator right. I want to understand how the "<>" (empty Diamond operator)" works in a "while"loop.
Here is my code ( the script is saved as diamond.pl):
#!/usr/bin/perl -w while (<>) { print ; }
Now i have two files called colors.txt and seasons.txt in the same directory as that of the above script. so if i run below command, it start printing the individual lines of both the .txt files:
perl diamond.pl colors.txt seasons.txt
and I understand above.
However, If I run below comamnds, it errors out;
perl diamond.pl these are words and not the file names
I get below eerror:
# perl diamond.pl these are words and not the file names Can't open these: No such file or directory at diamond.pl line 2. Can't open are: No such file or directory at diamond.pl line 2. Can't open words: No such file or directory at diamond.pl line 2. Can't open and: No such file or directory at diamond.pl line 2. Can't open not: No such file or directory at diamond.pl line 2. Can't open the: No such file or directory at diamond.pl line 2. Can't open file: No such file or directory at diamond.pl line 2. Can't open names: No such file or directory at diamond.pl line 2.
My undestanding was (and this is mentioned on numerous pages on hte internet), the empty "<>" checks for the @ARGV. So in above command, I was hoping to see the output as one word of the sequence "these are words and not the file names" printed on each line.
I am pretty sure am doing something really dumb here. could you explain how an "<>" (empty) operators works in a while loop. An example of the script and the command would be of great help.
Thanks.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |