in reply to While issues
The code in your update is functionally different than your original code. Did you mean to go from finding one non-empty element to two? (original: $cnr < 1 vs new: $cnr <= 1).
Also, it loops more than necessary. The following fixes this and simplifies the code:
my $cnr = 2; for my $xda ( shuffle 0 .. $total ) { if ( defined $aob[$xda][ $y - 1 ] ) { $aob[$x][$y] = $z + $aob[$xda][ $y - 1 ]; last if --$cnr == 0; } }
Or if you mean to only find one non-empty element:
for my $xda ( shuffle 0 .. $total ) { if ( defined $aob[$xda][ $y - 1 ] ) { $aob[$x][$y] = $z + $aob[$xda][ $y - 1 ]; last; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: While issues
by Dandello (Monk) on Feb 03, 2011 at 16:36 UTC |