in reply to Re^4: Problem with regex wildcard operator (.)...?
in thread Problem with regex wildcard operator (.)...?

I am not sure why your code seems to work.

It works because \[ is just an escaped [, so tr/\[A-Z]/[a-z]/ is translating [ to [, ] to ], and uppercase to lowercase. Any other character, e.g., \, is unaffected.

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

Replies are listed 'Best First'.
Re^6: Problem with regex wildcard operator (.)...?
by Marshall (Canon) on Sep 06, 2021 at 07:35 UTC
    Thanks for the explanation! I did not think that an escape '\' would work within TR. Even though that does indeed work, I prefer my tr/A-Z/a-z/ because it is easy for me to understand it at a glance. Of course, mileage varies.
      I prefer ... tr/A-Z/a-z/ ...

      So do I - or better yet lc in this case. :)

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

        Yes, lc() is rocket fast because this only involves fiddling with one bit within a byte. C and ASM can do this very, very quickly. This is just a minor point in the OP's code. This is in a "run once" initialization loop. No optimization here will make any difference at all in terms of user perceived performance.

        The OP does have a correct idea in that running a regex against all lines of the input dictionary will be so fast, that the complexity of that regex probably makes no difference at all. The idea of throwing away extraneous results that are either too long or too short in terms of number of characters also probably makes no difference.

        I think the problem here is that we do not have clearly defined textual description (meaning something that a human can understand) of what the code is supposed to do! Nobody here can "fix" code that doesn't do what it is supposed to do, if we don't know what it is supposed to do in the first place!