I thought I had some proficiency with regular expressions...until I met perl...
The goal was a substitution in which literal square brackets were to be part of the replacement text and in which certain variables would be used in the replacement as well. I had assumed that the brackets would be treated as literals. Wrong. Following are examples of the kinds of results I got:
$s = 'now is the time for all good etc.;' $bef = 'before'; $mid = 'middle'; $aft = 'after'; Regexp: result (was it expected?) s/.+/$bef$mid$aft/: beforemiddleafter (expected result, if no brackets) s/.+/$bef[$mid$aft/: (SYNTAX ERROR: "scalar found where operator expected"...) s/.+/[$bef]$mid$aft/: [before]middleafter (expected) s/.+/$bef[$mid]$aft/: after (huh?) s/.+/$bef$mid[$aft]/: before (whaa?)
So much for proficiency. I had been aware that not every possible
sort of text is taken literally on the "replace-with" side of the substitution,
but I was unprepared for the above results. I need to do some more reading.
Which of the sundry books on perl would provide the best information about
what is happening in these kinds of substitutions?
T.I.A. . . .
In reply to Regexp: not what I'd expected by greenhorn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |