Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found