P is for Practical | |
PerlMonks |
Strange Smart Match behaviorby OverlordQ (Hermit) |
on May 26, 2011 at 19:31 UTC ( [id://906887]=perlquestion: print w/replies, xml ) | Need Help?? |
OverlordQ has asked for the wisdom of the Perl Monks concerning the following question:
What my intended purpose is to take the return value of a function call that gets the status of our object and compares it to an array of 'valid' statuses.
psudo code for this is effectively:
Now the issue came up that our error checking on the load call isn't optimal, so we didn't throw an error when we should. My train of thought then went too, well if we created an invalid object, we cant get the status of it and so the smart match will fail. However it doesnt. From what I can tell the string is defined, but empty, with some weird properties. My minimal test case is as follows: Running this you recieve the following output: First thing to note is from Dumper, they look the same. Devel::Peek gives a bit different picture though. Now the weirdness (imo) comes in during the smart match, despite them appearing to be the exact same thing, the mystery value matches successfully while the empty string doesn't. EDIT: But it doesn't stop there. Let's add an equality check. If we throw in: if ( $mystery eq $empty ) { print "ASCII Equal!\n"; } in there, we get So they're equal . . interesting. How about numerically? And we get: Wait, now Empty is valid too? Edit2: And in case anybody asks: And our Object module is based on Class::Std. Now the reproducibility of this might be impossible as I can't give up the module or the database, but I'd be more then willing to run code/modules/etc to diagnose.
Back to
Seekers of Perl Wisdom
|
|