in reply to More effective way to increase two elements of a list in parallel?
The inner while is useless, because after the first iteration it will always leave the inner while. You could write it this way instead:
for (3 .. 8) { my $pdu_num = $_; $pdu_num = 11 - $pdu_num unless defined $order; if (@nodes) { my $node = shift @nodes; $map{$node} = $pdu . '['.$pdu_num.']'; next; } }
Now you don't have nested loops anymore, so you don't need the label for next. (Actually you don't need the next at all, because it's the last statement in that loop)
Update: another slightly improved version:
for (3 .. 8) { my $pdu_num = $_; $pdu_num = 11 - $pdu_num unless defined $order; last unless @nodes; my $node = shift @nodes; $map{$node} = $pdu . '['.$pdu_num.']'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: More effective way to increase two elements of a list in parallel?
by et_alia (Initiate) on May 06, 2008 at 18:10 UTC |