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


In reply to Re: out of memory! by kcott
in thread out of memory! by rocketperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.