good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
According to the perlop documentation the regular expression match operator (m//) will return true if it finds a match or false if doesn't. Usually where Perl operators return false they do so by either returning an empty string or 0, however this doesn't appear to be the case for failed regular expression matches. Normally it doesn't matter as Perl being Perl just does what I intended, but earlier today I encountered a bug when assigning the result of regular expression match as part of initialising a hash - the following code exhibits the issue:
Running this code results in:
Eventually I realised that the failed match for the regular expression was somehow tricking the first comma to be evaluated in a scalar context, rather than a list context (note that if the regular expression matches then it returns 1 and the comma is evaluated in a list context). With this information I was able to fix the bug I had, but curiosity lead me to dig deeper into what was happening, so tried the following code:
From running this code it seems that the failed regular expression match is returning something that isn't really a traditional Perl value, but which does evaluate to false in most situations - a sort of "phantom" false value. Which leaves me with two questions:
|
|