slayedbylucifer has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to use empty "<>" (Diamond Operator) inside While loop
by choroba (Cardinal) on Jun 25, 2012 at 09:04 UTC | |
by zwon (Abbot) on Jun 25, 2012 at 13:08 UTC | |
|
Re: How to use empty "<>" (Diamond Operator) inside While loop
by CountZero (Bishop) on Jun 25, 2012 at 09:19 UTC | |
|
Re: How to use empty "<>" (Diamond Operator) inside While loop
by Athanasius (Archbishop) on Jun 25, 2012 at 09:09 UTC | |
|
Re: How to use empty "<>" (Diamond Operator) inside While loop
by tobyink (Canon) on Jun 25, 2012 at 09:57 UTC | |
|
Re: How to use empty "<>" (Diamond Operator) inside While loop
by Anonymous Monk on Jun 25, 2012 at 09:55 UTC | |
|
Re: How to use empty "<>" (Diamond Operator) inside While loop
by slayedbylucifer (Scribe) on Jun 27, 2012 at 03:04 UTC |