| Next | Program Repair Shop | 7 |

These are variables whose only purpose is to track the length of an array
But the array already tracks its own length
This can almost always be replaced:
my $num_items = scalar @array;
$array[$num_items] = $new_item;
Its purpose is to add an element to the end of @array
Perl already has a special built-in function for doing that:
push @array, $new_item;
Savings: one line of code, one variable
| Next | ![]() |
Copyright © 2006 M. J. Dominus |