<>;
print $_
But this works:
while(<>){
print $_;
}
Why doesn’t the first version work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
while (<>)is shorthand forwhile(defined($_ = <ARGV>)), but<>;is just<ARGV>;. You can see this with theB::Deparsemodule.Given the file
example.plthe command
will print
This is an example of Perl’s famous DWIMery. I believe it was done to stop people from doing the wasteful
There is no value to special casing
<>in void context, and, in fact, it would probably be harmful since when you say<>;you are most often trying to throw away a line you don’t want from the filehandle. Having$_catch it would not be efficient or desirable.