As an alternative to FunkyMonk's suggestion (essentially echoed by jasonk), you may want to keep your "sub nsqry" to answer just a single Name lookup.

If this is the case, you need to add one more loop :

for my $key (keys %AoH) { for my $domain qw(ns7.xxx.com wrnadc02.xx.xxxxxx.com) { nsqry($domain, $_ ) for @{$AoH{$key}} ; } }
By the way, your %AoH is really a HASH whose VALUES are Array-refs, and would probably be better named as "HoA".

I imagine (Having written similar functionality myself), that you may eventually want to associate the domain name with the IP-address when you find it. Your current data structure will make that association very complicated. Here is my suggested structure/code:

my @domain = ( {NAME => 'ns7.xxx.com', IPLIST => []} # IP +LIST gets populated dynamically, as discovered , {NAME => 'wrnadc02.xx.xxxxxx.com', IPLIST => []} ); my %IPinfo; # This will be a HoH for (qw (10.220.84.30 10.220.84.51 10.220.84.52 10.220.84.54 ...){ $IPinfo{$_}= {DOMAININDEX => undef, TYPE => "CLIENT"}; } .... OUTER: for my $ip (keys %IPinfo){ for my $domidx (0..$#domain){ my $ptr = nsquery($domain[$domidx]->{NAME}, $ip) ; # Assumi +ng "nsquery" has been modified to return the info next unless $ptr; # No change, if $ptr is empty $IPinfo{$ip}{DOMAININDEX} = $domidx; # Forward ref from IP +to DOMAIN $IPinfo{$ip}{PTR} = $ptr; push @{$domain[$domidx]->{IPLIST}}, $ip; # Keep a list of I +P's that live in this domain next OUTER; # we bail after the first domain found (More ef +ficient) } }

     "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom


In reply to Re: loop ending b4 I want it to by NetWallah
in thread loop ending b4 I want it to by mikejones

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.