Reputation: 39
What does the following Perl regular expression modifer do?
/o
For example,
$string =~ /foo\(\"([^\)]*)\"\)/o)
What does the /o
mean?
Upvotes: 1
Views: 354
Reputation: 153
It tells Perl to only compile the expression once. See What is /o really for?.
Upvotes: 6
Reputation: 385764
Absolutely nothing!
It affects interpolation, and nothing is being interpolated into that pattern.
Were there something interpolated, /o would cause the interpolation to only happen once, no matter how many times the match operator is executed.
>perl -E"for (['o','foo'],['a','bar'],['e','neo']) {
my ($pat, $s) = @$_; say $s =~ /$pat/ ? $& : 0 }"
o
a
e
>perl -E"for (['o','foo'],['a','bar'],['e','neo']) {
my ($pat, $s) = @$_; say $s =~ /$pat/o ? $& : 0 }"
o
0
o
Upvotes: 5
Reputation: 69027
The /o option for regular expressions (documented in perlop and perlreref) tells Perl to compile the regular expression only once. This is only useful when the pattern contains a variable. Perls 5.6 and later handle this automatically if the pattern does not change.
(source)
Upvotes: 5