Perl-o-Philes:
I, an ever slowly advancing Perl newbie have a question with a script I'm trying to build. (I's the third time I've posted- thanks everyone for your help up to now). What I've done so far is this:
Open a Pix logfile and pull all of our addresses out either to an array or a file.
Then, I redirect the content of file/array to the Unix process sort -u to get only one instance of each address.
Then, I am trying to run each IP through Nslookup.pm and return the IP and hostname to a hash to be use to do a search and replace on a copy of the original Pix log file. This will make checking the file much friendlier.
Now, here's the code I'm having trouble with:
while (<NS>) { $a = nslookup (host => "$_", type => "PTR"); %hosts($_, $a); }
Now, building the hash hasn't yet worked. I've tried several way to confirm the hash contents, but they are never there. So, how do I populate the hash with $_ being the key and $a the value? What I'll do next is call s///r against the original copy to search and replace the IPs with hostnames, thusly:
while ( ($ip, $a) = each (%hosts)) { foreach $line (@final) { s/$hosts{$1}/$hosts{$2}/g; print FQDN $_; } }
I've never been able to confirm that this is the appropriate method for searching a file based on contents in a hash.
Thanks again for all your Perl wisdom. Monger

In reply to Another NSlookup Question by monger

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.