You need to reset the each iterator. Using keys does that. Refactoring your code a little may help see what's going on. Consider:

use strict; while (my ($defNet, $defKey) = each (%defMaskArray)) { ... HOST: for (my $bCount = 1; $bCount <= $hostsN; $bCount++) { ... while (my ($n, $host) = each %$refHandle) { ... my $testResult = test ($bCount, $boundary, $host, $defNet, $de +fKey, \@routeArray); keys %$refHandle if $testResult ne 'ok'; # Reset each redo HOST if $testResult eq 'retry'; next HOST if $testResult eq 'greater'; } ... } } sub test { my ($bCount, $boundary, $host, $defNet, $defKey, $routeArray, ) = +@_; for (my $iCount = 0; $iCount <= 256; $iCount = ($iCount + $boundar +y)) { # evaluate boundaries if ($iCount == $host || (($iCount + $boundary) - 1) == $host) +{ print OUT "$defNet for $host fell on a boundary for mask - $boun +dary\n"; if ($boundary == 256) { ... } else { ... return 'retry'; } } elsif ($iCount > $host) { ... return 'greater'; } else { ... } } return 'ok'; }

Note too that you should use strictures (use strict; use warnings;) and generally avoid using $a and $b except for their magical use in the context of sort.


Perl is environmentally friendly - it saves trees

In reply to Re: Resetting Internal Loop Pointers by GrandFather
in thread Resetting Internal Loop Pointers by ddanatzko

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.