Greeting all,
I have this code so far but I am trying to figure out how to sort on the hashes I have built in my sub routine, where I am getting a bit confused is the returned value from my nslookup will not always be in the same order so ip for ns1.t might not be the first, but the second or last. With that said will my sort still work or should I build my hashes as a hash of an array?? This is really confusing to me and I really have no idea where to start. Any help you might offer would be great.

SUNADMN
USE PERL
#!/usr/bin/perl use strict; use Net::Nslookup; my $input = '/var/tmp/clean'; my $ours = '/var/tmp/ours'; my $theirs = '/var/tmp/theirs'; my $unknown = '/var/tmp/unknown'; open(IN, "$input") || die "Can't open $input\nReason: $!\n"; open(OUT, ">$ours") || die "Can't create $ours\nReason: $!\n"; open(OUT1, ">$theirs") || die "Can't create $theirs\nReason: $!\n"; open(OUT2, ">$unknown") || die "Can't create $unknown\nReason: $!\n"; my @ns; while(<IN>) { my $domain = $_; chomp $domain; @ns = nslookup(domain => "$domain", type => "NS"); &ours; # for(@ns) { # print "@ns\n"; # } } sub ours { my %ours ( '24.56.102.10' => ns1.t, '24.56.100.10' => ns2.t, '24.56.100.11' => ns3.t ) my %theirs ( '68.168.192.17' => ns1.a, '24.50.78.2' => ns2.a, '68.168.224.177' => ns3.a ( if($ours{ns1.t}) { print OUT "$_\n"; } elseif($theirs{ns1.a}) { print OUT1 "$_\n"; } } close(IN); close(OUT); close(OUT1); close(OUT2); exit;

In reply to To Hash or Not to Hash?? by sunadmn

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.