Hi,
for the mongodb driver, it seems i have to use the qr// format of regular expressions.
from the documentation, :
Use qr/.../ to use a regular expression in a query .....
my $cursor = $collection->query({"name" => qr/[Jj]oh?n/});
The problem is that i have to create the query by reading existing mongo regex strings, e.g.
{"name" => '/.*uba$/i'}
i tried changing this through basic string manipulation to prepend the qr :
{"name" => 'qr/.*uba$/i'}
but i think it's just treating that as a string for full matching instead of applying it is a regex. it's certainly not working.
i also tried (after prepending the qr) passing it to a function and creating a qr object:
if(index($_[0],"qr/") >= 0){
$_[0] =~s/qr(.*?)(i?)$/$1/s;
print $fh Dumper($_[0]);
if($2=='i'){
my $re = qr/$_[0]/i;
}else{
my $re = qr/$_[0]/;
}
$_[0] =$re;
print $fh Dumper($_[0]);
}
but that outputs:
$VAR1 = '/.*uba$/';
$VAR1 = undef;
I'm very new to perl, so it's very possible that i'm missing something obvious. any ideas?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.