The short question:
I need to use variables in a regex, these variables contain filenames, these filenames contain every character under the sun including regex special character. I need to knwo how to use a variable within a regex when it might have characters that screw with the regex.
here is the code sample for where my program messes up and an example of an error:
$Title =~ s,^$Artist\s*-\s*,,ig; //Remove artist name from string
/stuff/Audio/Techno/Trance[]Control
Unmatched [ in regex; marked by <-- HERE in m/^trance[ <-- HERE ]contr
+ol\s*-\s*/ at ./builddb.pl line 121.
--In this case the artist name is: Trance[]Control
I have tried writing my own clean functions that escape characters but Ia lways miss something and find out long after that I messed up once it is too late to do anything about it.
The situation description:
Basically I am running scripts that I am writing as I need them, these script are fixing some major problems in a set of over 30,000 files and it deals with both file name info and meta info to try and make sence of it all. Using perl I have made TONS of progress. However these files can have any character including
(,),[,]
-Exodist
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.