Next | Program Repair Shop | 192 |
Getting the length of the array:
$n_elements = $#array;
Of course, this is actually wrong; it should have been:
$n_elements = $#array + 1;
But better is:
$n_elements = @array;
Often you can dispense with $n_elements entirely
Instead of this:
$n_elements = $#array; if ($n_elements < 3) { ... }
Just use:
if (@array < 4) { ... }
Say what you mean
Next | Copyright © 2002 M. J. Dominus |