Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

strings contain regular expression characters

by onegative (Scribe)
on May 24, 2009 at 16:56 UTC ( [id://765936]=perlquestion: print w/replies, xml ) Need Help??

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.
Thanks,
Danny

  • 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
    quotemeta()

    CountZero

    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

      Kewl!!!...

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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://765936]
Approved by Corion
Front-paged by starX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found