in reply to Q regex escape within variable

It's hard to understand just what you're trying to do. Can you please give a Short, Self-Contained, Correct Example? Giving  $fname a value and populating the  @fNames array with a few typical values along with the corresponding expected contents of the  @matchIndexes array would go a long way toward making things clearer. The line number of the warning message generated by the SSCCE will be helpful.


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

Replies are listed 'Best First'.
Re^2: Q regex escape within variable
by palkia (Monk) on Mar 28, 2017 at 10:17 UTC
    Hello.
    I'm sorry if my explanation was insufficiently clear.

    The reason I omitted most of my code as well as the line number, was that experimenting confirmed that the code lines I've posted were the only ones responsible for the error, and independently of $fName's value.

    The error generating part was $fNames[$mex] =~ /$pref/i,
    which was intended to return true when for example $fName began with '[case A.2 v6]' and $fNames[$mex] began with the exact same string except that the numbers could have been any other numbers as well, such as '[case A.99 v0]' or '[Case A.1 v123]' but not '[case B.2 v6]'.

    Once I have constructed the list of indexes of matching names, I could refer to the subarray and work on it specifically, such as ignoring the prefix and sorting the names independently of it.

    I hope this clears things up (but notice the above update saying the problem has been solved already).
    Thank you very much.