There are two different layers of processing here. First, Perl applies the standard interpolations for double-quoted ("qq") strings to get a regex. Second, Perl interprets the string it produced in the first step as a regex.
The $ character is special in both of these contexts: in qq-string interpolation it introduces a variable substitution and in a regular expression (from which Perl regexes inherit their basic features) it is a special atom matching "end of line". The problem in this program is that we need to interpolate a string obtained from Tk such that when the user enters "abc$def", the regex engine will actually match that exact string, so we need the first step to produce 'abc\$def' with a backslash to escape the $ character. This is what quotemeta does, and using "\Q$foo\E" is shorthand for my $tmp = quotemeta $foo; and "$tmp" but probably more efficient.
A simple \$ prevents the interpolation in the first step. Using "\$foo" happens to be equivalent to '$foo', which would be a fixed search pattern and unlikely to be useful in the questioner's program.
Another option would be to document that the program accepts regexes instead of fixed strings and require the user to enter 'abc\$def' if a match for the literal string 'abc$def' is desired.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||