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:
my $obj = ObjectStuff->load(objid); my $status = $obj->getStatus(); my @validStatus = split(',', $csv_of_active_status); unless ( $status ~~ @validStatus ) { #spew warnings; exit; }
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:
#!/usr/bin/perl use Object::Module; use Data::Dumper; my $obj = Object::Module::load({id => 'OMGWTFBBQ'}); die unless $obj; my @goodStatus = ... my $mystery = $obj->get_status(); use Devel::Peek; print "mystery Dump\n--------\n"; print Dumper($mystery); print "\nmystery Peek\n--------\n"; Dump($mystery); my $empty = ''; print "\nEmpty Dump\n--------\n"; print Dumper($empty); print "\nEmpty Peek\n--------\n"; Dump($empty); if ( defined $mystery ) { print "mystery defined\n"; } if ( defined $empty ) { print "Empty defined\n"; } print "\nArray Dump\n--------\n"; print Dumper(@goodStatus); if( ($mystery) ~~ @goodStatus ) { print "Status is valid!\n"; } if( ($empty) ~~ @goodStatus ) { print "Empty is valid!\n"; }
Running this you recieve the following output:
mystery Dump -------- $VAR1 = ''; mystery Peek -------- SV = PVNV(0xa5317e4) at 0x982ec48 REFCNT = 1 FLAGS = (PADMY,IOK,NOK,POK,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x9b36a68 ""\0 CUR = 0 LEN = 4 Empty Dump -------- $VAR1 = ''; Empty Peek -------- SV = PV(0xa50ea88) at 0x9d6e6f0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0xa48f740 ""\0 CUR = 0 LEN = 4 mystery defined Empty defined Array Dump -------- $VAR1 = '128'; $VAR2 = '1'; $VAR3 = '0'; $VAR4 = '-3'; Status is valid!
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
... Empty defined ASCII Equal! Array Dump -------- $VAR1 = '128'; $VAR2 = '1'; $VAR3 = '0'; $VAR4 = '-3'; Status is valid!
So they're equal . . interesting. How about numerically?
if ( $mystery == $empty ) { print "Number Equal!\n"; }
And we get:
ASCII Equal! Number Equal! Array Dump -------- $VAR1 = '128'; $VAR2 = '1'; $VAR3 = '0'; $VAR4 = '-3'; Status is valid! Empty is valid!
Wait, now Empty is valid too?

Edit2: And in case anybody asks:
$ perl -v This is perl, v5.10.0 built for i486-linux-gnu-thread-multi
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.

In reply to Strange Smart Match behavior by OverlordQ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.