Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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?

In reply to creating qr from existing regex by Bobert1234

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

  • 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 or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2022-01-26 09:13 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (69 votes). Check out past polls.