Regular Expressions   «Prev 

Perl e Substitution Modifier

The e modifier is used if you want the right-hand side of the substitution to be evaluated as code, instead of being treated as a string. For example,

s/$(\w+)//e;

That will replace anything that looks like a Perl scalar variable with the contents of that variable. This is extremely useful for embedding values in a text file.
Let us look at this example more closely:

Regular Expressions
The user is referring to a variable name $money. so the substitution must evaluate this as code instead of as a string.

This line of code will do the substitution

Matches the dollar sign in before money

matches any word that comes after the dollar sign. The brackets tell the Perl program to remember what matched the \w+ and stores that in the variable $l.

refers to the first item in parentheses in a matching string

makes the item a scalar variable

tells the Perl program to treat the resulting string as a Perl variable, not a literal string

The result is the Perl variable money