An Introduction to Regular Expressions The Substitution Operator 35 of 50 : [PREV] [NEXT]

Modifiers

The /o Modifier

There are some instances, where a variable will contain the same value each time it is used in an expression. This is when we would use the /o modifier. The /o modifier tells the RegEx Engine to resolve any variables only once, and to remember the REPLACEMENT string for this substitution.

my $string = "abc";
foreach my $value (@values) {
  $value =~ s/^/$string/o;
}

If we didn't use the /o modifier, each REPLACEMENT string would have to be resolved to "abc" before the regular expression could be created.


© 2003 Barbie barbie@missbarbell.co.uk Home http://birmingham.pm.org/