abubacker has asked for the wisdom of the Perl Monks concerning the following question:

Dear all,
what is the purpose of 'o' modifier in m operator
for ex : m#patttern#o
what it will do

Replies are listed 'Best First'.
Re: usage of o modifer
by ikegami (Patriarch) on Aug 13, 2009 at 04:44 UTC
    It interpolates once and remembers that value.
    for my $word (qw( abc def )) { print $word =~ /\Q$word/ ?1:0,"\n"; # 1 1 } for my $word (qw( abc def )) { print $word =~ /\Q$word/o ?1:0,"\n"; # 1 0 }

    It's was used to prevent a regex pattern from being compiled repeatedly, but Perl does that even without "o" now. And between the check to skip unecessary compiles and qr//, the "o" modifier is no longer needed.

Re: usage of o modifer
by Anonymous Monk on Aug 13, 2009 at 04:18 UTC