monger has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Another NSlookup Question
by naChoZ (Curate) on Aug 15, 2003 at 19:29 UTC
    To assign the value to the hash, just do $hosts{$_} = $a;

    However, one way you might be able to do this is with an in place edit. Check this thread for inspiration.

    --
    "I just read perlman:perlboot," said Tom, objectively.
    naChoZ

    UPDATE: doh! just as I hit submit, the correct term occurred to me, "log resolver"

    this one was written for web logs, but I'm sure it would be easily adaptable.