note
vr
<p>Not an answer, just a comment. Do I get it right:</p>
<ul>
<li>"setter" (in quotes, because I understand it's not really a setter) accepts a compiled regex, one you build with the <c>qr</c> operator;</li>
<li>"getter" returns not this compiled regex, but, somehow, Perl source code fragment, literal string <c>'qr/.*uba$/i'</c>. Which you then are trying to parse. Or, where does this <c>'qr/.*uba$/i'</c> come from, and why is it necessary to manually parse Perl expression?</li>
</ul>
<p>It doesn't make much sense to me, but I haven't worked with MongoDB, hence not an answer, but a promised comment. The reason you get an <c>undef</c> in OP, is because <c>$re</c> are 2 separate lexical variables, 1 per each own small block. They are declared with <c>my</c> and destroyed at closing curly bracket. What's assigned to <c>$_[0]</c>, in next line, is presumably global, completely different <c>$re</c>, and undefined at that time. You don't <c>use strict;</c>, do you? I think this change</p>
<c>
my $re;
if($2 eq 'i'){
$re = qr/$_[0]/i;
}else{
$re = qr/$_[0]/;
}
$_[0] =$re;
</c>
<p>would give you the result you were hoping for.</p>
<p></p>
<p><b>Edit:</b> Fixed numeric comparison operator to string comparison <c>eq</c> (thanks, [poj]). </p>
1208734
1208734