The stupid question is the question not asked | |
PerlMonks |
Disable Regexby SavannahLion (Pilgrim) |
on Aug 26, 2009 at 05:38 UTC ( [id://791255]=perlquestion: print w/replies, xml ) | Need Help?? |
SavannahLion has asked for the wisdom of the Perl Monks concerning the following question: How do I disable or prevent Perl from processing special regex characters such as \, * and ? in a quoted string so I can process them as regular characters? I'm stuck on this one. I'm pulling data from a couple of sources and amongst the many chunks of information I'm sucking up, the darn thing kept choking. Come to find out there are a couple of "illegal" characters that's causing problems for me. For example, some characters like \, * and ? (amongst others) are triggering problems elsewhere within the code. Unfortunately, I can't just send these characters on their merry way since the some of this data is being converted into files on an NTFS partition. In other words. I'm slurping down data from files (roughly 30GB worth of data). The data within is digested and new NTFS palatable files are created. Perl did exactly what I wanted it to do with the exception of the file naming convention. To my surprise, Linux happily wrote illegal Windows characters to the NTFS partition causing Windows to balk when trying to do anything with them. In other words, Linux (and Perl) created files such as: OK..... Looking back and my internal file structure, I finally decided to do a bit of substitution making \, * and ? into [bs], [a], [q]. Yaaay! It started working. Until I ran into files that needed to be ab\delta.txt and ab\\delta.txt. I was getting ab[bs]delta.txt. DOH!! So here's what I've come up with so far (with all the extranous crusty stuff removed):
Nice, it produces what I want: illegal[bs]characters[a]example[q]. However if I modify $test to equal 'illegal\\characters\*example?' I get illegal[bs]characters[bs][a]example[q] when it should read illegal[bs][bs]characters[bs][a]example[q] (note the missing [bs] after illegal). I've been trying all sorts of ideas to supress the \\ being escaped, but I'm stuck. Please, enlighten me and direct me to the proper solution.
Back to
Seekers of Perl Wisdom
|
|