In my book it uses something like this:
for($ARGV[0])
{
Expression && do { print "..."; last; };
...
}
Isn’t the for-loop incomplete? Also, what’s the point of the do, couldn’t it just be { ... }, or does the do have some importance here?
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.
There are two forms of
forstatement in Perl. The one you’re seeing here is often written asforeach, butforandforeachare synonyms. It normally iterates over a list, setting$_to each element. In this case, the “list” is a single value, so it has the effect of setting$_to$ARGV[0]for the body of the loop.The
dois needed to make the block{ ... }into an expression, so it can be an operand of the&&operator. (See what happens if you omit the worddo.)(And you were missing a semicolon; I’ve edited the question to fix that.)