Is there any reason to use a scalar comma operator anywhere other than in a for loop?
Since the Perl scalar comma is a "port" of the C comma operator, these comments are probably apropos:
Once in a while, you find yourself in a situation in which C expects a single expression, but you have two things you want to say. The most common (and in fact the only common) example is in a
forloop, specifically the first and third controlling expressions. What if (for example) you want to have a loop in whichicounts up from0to10at the same time thatjis counting down from10to0?
So, your instinct that it's mainly useful in for loops is a good one, I think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With