I’m still mostly uncertain what you’re trying to do. However, looking at the three lines of code that you have below, you’re correct in that the brackets will make $a=~/$b/ return undef (by the way, the third line is a no-op, since you aren’t doing anything with any potential matches…). What you need is the quotemeta function (http://perldoc.perl.org/functions/quotemeta.html):
$a=”abc[0]”; $b=”bc[0]”; $c=quotemeta($b); # $c eq ‘bc\[0\]’; If($a=~/$c/){print “match\n”;} # results in “match” being printed. From: xiyoulaoyuanjia [mailto:xiyoulaoyuan...@gmail.com] Sent: Wednesday, July 11, 2012 11:46 PM To: Jack Maney Cc: beginners@perl.org Subject: Re: regular error i am very sorry ! i am intend to parse variable $a by the regular variable $b . in below way! ---------------------------------------- $a="abc[0]"; $b="bc[0]"; $a=~/$b/; --------------------------------------------- but it can not parse right ! just because the "[" symbol。 i kow $a=~/abc\[0]/ it can get right! but when regular is a varible . I do not know how to solve it? Sorry if this isn't clear let me know if there are any questions. thanks in advance! 2012/7/12 Jack Maney <jma...@adknowledge.com<mailto:jma...@adknowledge.com>> I don't understand what you're trying to say or do. Exactly what error message are you getting? -----Original Message----- From: xiyoulaoyuanjia [mailto:xiyoulaoyuan...@gmail.com<mailto:xiyoulaoyuan...@gmail.com>] Sent: Wednesday, July 11, 2012 10:54 PM To: beginners@perl.org<mailto:beginners@perl.org> Subject: regular error *hi all:* * i have an error in below * regular ---------------------------------------- $a="abc[0]"; $b="bc[0]"; $a=~/$b/; --------------------------------------------- how can i do in this way? thanks ! -- 继续上路。。 you can follow me at twitter @xiyoulaoyuanjia -- 继续上路。。 you can follow me at twitter @xiyoulaoyuanjia