| [reply] [Watch: Dir/Any] [d/l] |
$found =~ s/
ENV{\" # match the characters: ENV{"
(.*?) # followed by any characters -- this sequence
+is the "value", and the parentheses capture it into the special varia
+ble $1
\"} # followed by: "}
/
\$ENV( # and substitute a literal: $ENV("
$1 # followed by the captured "value"
\") # followed by: ")
/gx; # and repeat the search & replacement to the e
+nd of $found
Notes:
-
The double quotes are backslashed only because I was using a one-liner (and I’m on Windows). This is unnecessary in a .pl script. (But the $ must be backslashed to show that it is literal, not the special symbol for “match the end of a line” (in the search part) or a sigil denoting a scalar variable to be interpolated (in the replacement part). Update: Added the words from “(in the search part)” to the end of the sentence.)
-
The ? in the capture group (.*?) makes the match non-greedy. So the regex engine looks for the fewest number of characters occurring between ENV{" and "}. Without the ?, the match would be greedy, and on the string:
ENV{"VCINSTALLDIR"}\ATLMFC\LIB\amd64;ENV{"LIBPATH"}
it would match
VCINSTALLDIR"}\ATLMFC\LIB\amd64;ENV{"LIBPATH
which is not what we want!
Hope that helps,
| [reply] [Watch: Dir/Any] [d/l] [select] |
| [reply] [Watch: Dir/Any] |