I tend to write something like that as:
while( my( $first, $second ) = map { ... } 1..2 ) {
...
}
You may not like that syntax because you aren't used to doing things that way, but it follows a couple rules that I think make code easier:
- I don't type the same thing twice
- I assign to all the variables at once
- I use the map to generate the list when I need to run something more than once.
- I don't use logical operators gratuitously.
However, there's another problem. You have to figure out what you are really testing in the while
condition, and make that apparent to the next programmer. I'm not sure why you have two things in that condition. Is it okay to read the iterator if there is only one thing (i.e. what happens to the unprocessed odd man out)?
A much better solution would be some way that you show what you are trying to do without showing the mechanics. Not knowing anything about your iterator, I might suggest that you decorate it with another method that returns two items (or maybe the empty list if it is at the end):
while( my( $first, $second ) = $iterator->read_two ) {
...;
}
If that doesn't make the situation clear, decorate it with a method to ask a particular question:
while( $iterator->two_things_left ) {
my( $first, $second ) = $iterator->read_two;
...;
}