Problems? Is your data what you think it is? | |
PerlMonks |
Dangers of decode_json? or a hash entry is both defined and undefined. WTF?by varneraa (Acolyte) |
on Jun 02, 2020 at 04:07 UTC ( [id://11117581]=perlquestion: print w/replies, xml ) | Need Help?? |
varneraa has asked for the wisdom of the Perl Monks concerning the following question:
This new DB project just isn't being nice to me. Part of a new DB that I am putting together has a normalization table for services that we have organized into pools of machines. I was attempting to uniquify an array of strings and I noticed that my input array of 30k elements became an output of one undef entry. I figured uniq from List::MoreUtils, must just have a bug and I would just have to move on with something myself, even though it works on 10 other tables I'm uniquifying. The server names are standard fqdn that are alphanumeric with period separators.
So I decided to just uniquify the list myself, it's only 30k entries, right? So I put together this, I know it's inefficient, but I figured it out later
Guess what? It fails. "Use of uninitialized value in concatenation (.) or string at...<The line that assigns the $output_hash{$row->{$pk}} = 1;>" Ok, great, there is an undefined value in a row from $machine_aref, right? Yes, but no, but yes? A little more debug code later and I have this...
Surely we're going to hit the unless block and everything will be undef, right? Yes and no and yes again...
So I see that $row->{$pk} is undefined for this row, but I can dump the row and see that $pk matches exactly, remember this works for every other entry in the array, and then it fails again when I try to print the value. WTF? After this, I decided it was worth seeing which value(s) caused the problem. Turns out it was the first one, and the second, and wait, I guess all of them... So I switched the output of the command I was using to one that would just give me comma-delimited values and now everything works, including uniq. I still wish I understood what went wrong. If anyone is seeing a similar issue, I'm sorry this is a dead end. If someone with more expertise than me understands what is going on, I'd love you feedback. As always, thanks! Some final details: Perl 5.30.2 built using perlbrew on SLES11 - Linux 3.0.101-108.87-default
Back to
Seekers of Perl Wisdom
|
|