in reply to Re^2: how to use string RE (against $_ and capture)
in thread how to use string RE (against $_ and capture)

... how, after "$re_str" has been stringified, would the code know the string is meant to be used as a regexp instead of a direct compare.

The code "knows" because the string is used by a   =~  m//  s/// (I think that's all of them) matching operator. And what's a "direct compare" anyway?


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^4: how to use string RE (against $_ and capture)
by perl-diddler (Chaplain) on Nov 08, 2016 at 04:30 UTC
    If one's key is in '$_', direct compare is either "$_ eq 'x'" or in this case, using "$_" as a hash key, directly and not trying to match it to a Regex.

    Thus my need to know if a key in the table is a literal or a regex so I can do the right test to see if the key matches.

      You seem to be talking about doing what I would refer to as an exact match versus a pattern match. This information would IMHO be best stored as a separate piece of data in your data structure.


      Give a man a fish:  <%-{-{-{-<

      Thus my need to know if a key in the table is a literal or a regex so I can do the right test to see if the key matches
      Since the regex will have been stringified if used as a hash key, The only way I can think of doing that (if you can't store extra info in the hash value to indicate this) is to see if the key string matches /^\(\?.*\)$/. This will of course fail if an exact string match looks like "(?....)"

      Dave.