How Can I reset the internal pointer of a while loop back to the first element in the list? I'm trying to use a redo from a for loop to another for loop which has a while loop in between them, but the internal pointer of the while loop remains the same instead of starting at the beginning element again. udpate: code follows
MASK: while (my($defNet,$defKey) = each (%defMaskArray)){ print OUT "Starting new Subnet - $defNet\n"; $boundary = $defKey; # set boundary to key by default and allow fo +r it to be modified print OUT "Working: $defNet maskKey $boundary for $subCount{$defN +et} hosts\n"; my $refHandle = $subArray{$defNet}; # create a hash reference for +the subnet subHash my $hostsN = $subCount{$defNet}; # get number of hosts from subCou +nt hash HOST: for ($b = 1; $b <= $hostsN; $b++){ # track number of hosts +in Subnet so we know when to stop print OUT "Current iteration is $b\n"; NET: while (my($n, $host) = each %$refHandle){ # loop through + hosts in subnet subhash print OUT "| Subnet: ".$defNet."| Original Mask: $defKey +"."| Current Mask: ".$boundary."| IP: ".$host."| host #: $b"."\n"; TEST: for ($i = 0; $i <= 256; $i = ($i + $boundary)){ # e +valuate boundaries if ($i == $host || (($i + $boundary) - 1) == $host){ print OUT "$defNet for $host fell on a boundary fo +r mask - $boundary\n"; if ($boundary == 256){ print OUT "Current Sub: $defNet Mask: 256\n"; push (@routeArray, $defNet."/24") } else{ $boundary = ($boundary * 2); print OUT "test for $host failed - retrying wi +th $boundary after $b hosts attempted - original was $defKey\n"; $i = 0; redo HOST; } } elsif ($i > $host){ print OUT "$i is Greater then $host, no need to te +st further. Value of B is $b. Next Host.\n"; next HOST; } else{ print OUT "Host $host passed for $i - this is host + # $b with a default of $defKey\n"; } } } print OUT "# of Hosts: ".$b." Original Mask: ".$defKey." New + Mask: ".$boundary."\n"; print OUT "#################################################\n +"; $trueMaskArray{$defNet} = $boundary; } }

In reply to 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.