onegative has asked for the wisdom of the Perl Monks concerning the following question:

G'day Monks,
I am trying to figure out how to accept a string which contains regular expression characters as part of the string's value but do not represent regEx functionality to grep that string out of another array with the perl grep function but to escape it as a literal character???

string examples:

string = DB2$PB

string = SYSA$

So I am extracting this string from one array and then trying to use perl's grep to verify its existence in another array. The problem is that I am not sure how I can convert the extracted string's special characters to have an escape in front of them? I tried using substitution but again the $ is being read as a regEx character. Any help would be greatly appreciated.

  • Comment on strings contain regular expression characters

Replies are listed 'Best First'.
Re: strings contain regular expression characters
by CountZero (Bishop) on May 24, 2009 at 17:04 UTC


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


      Thanks for the help...exactly what I needed...

        We can use ' or q() as well.. quotemeta was absolutely right option