s/.+/$bef[$mid$aft/: (SYNTAX ERROR: "scalar found where operator expected"...)
should be written as:
s/.+/$bef\[$mid$aft/;
There are many characters that need to be escaped in regular expressions. The bracket could be interpreted either as the beginning and end of a character class ( example [a-z]), or as a subscript for an array (example: $bef[4]). In this case it's probably the later, since I don't think perl can make any sense out of a character class in a replacement expression. By putting a backslash in front of the bracket it looses its special meaning. Some other characters that have a special meaning are $," and /.
Then there are other perfectly normal characters that take on a special meaning when preceded by a backslash in a regular expression, e.g. \d (digit character), \s (any whitespace character), \S (anything that isn't a white space character).
The place to look for this kind of information is the perlre section of the perl man pages. If you're on Unix or similar, type "man perlre" at the command line (without the quotes). If you're on windows click the perlre link in the HTML documentation.
Hope this helps, /jeorgen
In reply to RE: Regexp: not what I'd expected
by jeorgen
in thread Regexp: not what I'd expected
by greenhorn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |