in reply to out of memory!
G'day rocketperl,
I see you've already received some good pointers; here's a few more.
$a and $b are special variables: don't use them except for their intended purpose (see perlvar). Also, you've neither declared nor initialised $b.
There's seven arrays that you use without declaring or initialising them: @blocks, @dist, @dump, @start, @sta, @stop, @sto. Furthermore, @sta and @sto are poorly named and could easily be confused with (or mistyped as or for) @start and @stop; as such, this represents many opportunities for potential errors.
You have other variables that appear to leap into existence without declaration or initialisation (such as $flag and $index). strict will alert you to undeclared variables (except special ones like $b) and warnings may point out uninitialised variables (depending on context) as well as other potential problems (as ++hdb has already alluded to).
do { ... } until (...); is a highly confusing construct in itself; regardless, in the context of the code you posted, it's completely unnecessary. Consider whether you think this is more readable and maintainable:
if ($dist[$b] >= 0) { while ($dist[$b] >= 0) { ... }
Your C-style for loop is overly complicated and prone to off-by-one errors. In fact, assuming you'd intended to use $i as an index for @blocks (see ++BrowserUk's comments on $i vs. $index), you do have an off-by-one error. Consider starting the loop as:
for my $i (0 .. $#blocks) {
You could probably write that even more succinctly as:
for (@blocks) {
but, without knowing exactly what's going with $i and $index, that may not be the case.
-- Ken
|
|---|