CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Comparing Arrays, Elements out of Sync

 



asrodgers
New User

Apr 7, 2008, 2:14 PM

Post #1 of 4 (724 views)
Comparing Arrays, Elements out of Sync Can't Post

I'm writing some housekeeping stuff and my issue in particular is with DNS and arrays. To make it short and sweet here is what I am doing and a short code snippet.

I have taken the last octet (ie 202, 203, etc) and made an array of them. I got around comparing them to an array clone of themselves to check for duplicate entries by splicing around any duplicates and continuing the evaluation. Well now I am comparing @REVERSEDNS to @FORWARDDNS and an exception (say 46 exists on one, but not the other) will cause both to be out of sync and every entry after this mismatch looks like an exception. I can't use a splice because I can't be sure which array is causing the issue, whether impossible to do or a sign of my feeble skills, I'm not sure...

Any help would be GREATLY appreciated, code is below and thanks in advance...

P.S... I have a function just like this below this one, just doing the same thing in reverse.


Code
@FORWARDdirty = @FORWARDDNSsorcery; 
@REVERSEdirty = @REVERSEDNSsorcery;

for ($i = 0; $i <= scalar(@FORWARDdirty); $i++) {
if ($FORWARDdirty[$i] eq $REVERSEdirty[$i]) {
} else {
print "\n\a[1] $FORWARDdirty[$i] does not have a matching IP entry in reverse DNS.";
print "\n\a[1] Yeah, you're up s*** creek without a paddle now buddy, your elements will never sync...";
$REDALERT = 1;
}
}


I suppose I should add that @FORWARDdirty and @REVERSEdirty contain all of the ip addresses, stripped of white space and the newline chomped off... if that makes any difference.


(This post was edited by asrodgers on Apr 7, 2008, 2:15 PM)


KevinR
Veteran


Apr 7, 2008, 11:14 PM

Post #2 of 4 (715 views)
Re: [asrodgers] Comparing Arrays, Elements out of Sync [In reply to] Can't Post

Post some sample data and show what it is you are comparing and where the problem is occuring. I am having a hard time understanding your question.
-------------------------------------------------


asrodgers
New User

Apr 8, 2008, 10:58 AM

Post #3 of 4 (710 views)
Re: [KevinR] Comparing Arrays, Elements out of Sync [In reply to] Can't Post

Not a problem, sorry for being unclear, I'm a bit scatter brained.

Essentially I am creating two arrays, a FORWARDdns and REVERSEdns array. Each array consists of the last octet of every IP in the zone file. I am comparing them against each other to check for missing entries. Essentially the for statement just steps down both arrays checking to see if the values in each element are equal or not equal. The trouble happens when it runs into an exception because then the elements are out of sync between both arrays, for example in the simplest terms...

@FORWARDDNS = (1,2,3,4,5,6,7,8,9);
@REVERSEDNS = (1,2,3,4,6,7,9);

All is well until we find the exception for 5, after that even though there are matching entries they appear as failures because the two arrays are out of sync. It will go on to compare 6 to 7, 7 to 9, 8 to nothing, and 9 to nothing.

Hope that brings a bit more clarity to my situation.


KevinR
Veteran


Apr 8, 2008, 6:57 PM

Post #4 of 4 (702 views)
Re: [asrodgers] Comparing Arrays, Elements out of Sync [In reply to] Can't Post

Your question is still not clear to me. I am not sure if you trying to compare the arrays index for index or just find if something in one array is not present in the other array (regardless of order or size of the arrays).
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives