We don't bite newbies here... much | |
PerlMonks |
Strings/Numbers aren't equating properlyby M4ver1k (Novice) |
on Feb 21, 2018 at 23:29 UTC ( [id://1209704]=perlquestion: print w/replies, xml ) | Need Help?? |
M4ver1k has asked for the wisdom of the Perl Monks concerning the following question: Edit: This is fixed. It was my fault...Flawed logic, it took time to work out. Explanation at the bottom of this post. I'm trying to compare results from an LDAP server to what lives on a MySQL server. Overall it works, right now I'm trying to optimize a part of it. I took the results of an LDAP query returning a single string value to an array '@ldap' which I then sorted alphabetically. Now I'm doing a search in MySQL, and as I iterate through the results, I'm comparing one column to the '@ldap' array and then I remove any matches out of '@ldap'. The problem is that sometimes, even though strings appear identical, it doesn't count it as a match and so fails to remove the match out of '@ldap', which creates redundant work at the end of the script. Here's the problematic code:
At first I thought it was because sometimes the strings contain only numbers, so I decided to check if they do contain only numbers, and if so, compare using '==' instead of 'eq'. I also was expecting to be able to use just $$info{'mid'} directly for comparison, so I did my $mid = $$info{'mid'}; for the sake of troubleshooting. In the file output, regardless of if they equate as strings or numbers, sometimes it just doesn't match when it looks like it should. Now I'm stumped. I'd be grateful for help, thank you! Edit: It's working now. My flawed logic was here:
I ended up having a lot more entries of type 'NA' than I was expecting, and due to work later in the script it ended up making more sense to put those entries into another array to separate out the work. So I changed the logic to this: I appreciate everyone's time, thank you.
Back to
Seekers of Perl Wisdom
|
|