Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 135827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:51:07+00:00 2026-05-11T06:51:07+00:00

It used to be considered beneficial to include the ‘o’ modifier at the end

  • 0

It used to be considered beneficial to include the ‘o’ modifier at the end of Perl regular expressions. The current Perl documentation does not even seem to list it, certainly not at the modifiers section of perlre.

Does it provide any benefit now?

It is still accepted, for reasons of backwards compatibility if nothing else.


As noted by J A Faucett and brian d foy, the ‘o’ modifier is still documented, if you find the right places to look (one of which is not the perlre documentation). It is mentioned in the perlop pages. It is also found in the perlreref pages.

As noted by Alan M in the accepted answer, the better modern technique is usually to use the qr// (quoted regex) operator.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:51:08+00:00Added an answer on May 11, 2026 at 6:51 am

    /o is deprecated. The simplest way to make sure a regex is compiled only once is to use use a regex object, like so:

    my $reg = qr/foo$bar/; 

    The interpolation of $bar is done when the variable $reg is initialized, and the cached, compiled regex will be used from then on within the enclosing scope. But sometimes you want the regex to be recompiled, because you want it to use the variable’s new value. Here’s the example Friedl used in The Book:

    sub CheckLogfileForToday() {   my $today = (qw<Sun Mon Tue Wed Thu Fri Sat>)[(localtime)[6]];    my $today_regex = qr/^$today:/i; # compiles once per function call    while (<LOGFILE>) {     if ($_ =~ $today_regex) {       ...     }   } } 

    Within the scope of the function, the value of $today_regex stays the same. But the next time the function is called, the regex will be recompiled with the new value of $today. If he had just used:

    if ($_ =~ m/^$today:/io) 

    …the regex would never be updated. So, with the object form you have the efficiency of /o without sacrificing flexibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this classic example used to explain what not to do with forward declarations:
Consider a private method which is called from JNI and not used otherwise, generating
In my perl code I've previously used the following two styles of writing which
I believe the below css is considered css3 if not then, it's not but
So I know it's considered somewhat good practice to always include curly braces for
I hope this question is considered appropriate for stackoverflow. If not, I'll remove the
The last time I used a regular expression was 2 years ago and even
Does the task parallel library have anything that would be considered a replacement or
Consider the following php code used for HTML output: echo <div id='logo2'> <a href='if(checkLanguage())
Consider the following C++11 code where class B is instantiated and used by multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.