Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re^2: program cant find values that start with $ by jcb
in thread program cant find values that start with $ by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found