s///o and qr// are pretty much the opposite of each other. If you make a regexp with the o argument you are basicly tellin the compiler that you will not change any of the variables associated with this regexp. Because of this perl will only ever compile this regexp once and will never change it, even if you do change the variables.

qr// is used to compare a string for use in a regexp. Consider the following:

$tofind = "some string"; while(<DATA>) { push @list, $_; } # Make a compiled list with qr @clist = map qr/$_/, @list; # Now run the two lists foreach (@list) { print "Found $tofind\n", last if($tofind =~ /$_/); } foreach (@clist) { print "Found $tofind\n", last if($tofind =~ /$_/); }

Warning: This code was written by a sleepy, coffee deprived programmer first thing in the morning. It has not been tested and may not run, explode and/or set fire to your computer.

The second loop, with @clist, will run faster as a lot of work has been done for the compiler already. Another possible use is when you have a list of patterns to match and you want to run some against certain rules (say case insensitivity) and some against others. You could either write a complicated set of subroutines or add extra data to flag which pattern had which requirement... or just precompile them all with qr!

$japh->{'Caillte'} = $me;

In reply to Re: difference between qr// and the use of the o modifier ? by Caillte
in thread difference between qr// and the use of the o modifier ? by arhuman

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.