I'm reading the "Beginning Perl" book, and it gives these two statements:
print "Test one: ", 6 > 3 && 3 > 4, "\n";
print "Test two: ", 6 > 3 and 3 > 4, "\n";
The first line prints nothing with a new line, the second line prints a 1 with no new line.
I'm confused about the output. According to the author, the second statement gives weird output because it's just like saying:
print ("Test two: ", 6 > 3) and 3 > 4, "\n";
However, why is the first statement not the same? I thought it had something to do with print's precedence. The && has higher precedence than print, so that's evaluated first and then it's printed. Whereas the "and" has lower precedence than print, so 6 > 3 will be printed, print returns a 1, and then that is evaluated with the "and." However this doesn't really make sense.
I've read the Perl documentation on how precedence works for list operators, but I still do not understand this example. Can you guys dissect the two statements, and tell me what is printed first? Can you also explain what the Perl documentation means when it mentions list operators as being "leftward" and "rightward?" Thanks.
Thanks a lot everyone for your answers. I understand it now. I was indeed doing what cjm said, and thinking that there are leftward and rightward list operators. So now that I understand what it means, I understand the whole thing.