On Mon, Jun 13, 2011 at 2:05 PM, eventual <eventualde...@yahoo.com> wrote:
> Hi, > I have a list of mp3 files in my computer and some of the file names > consists of a bracket like this "darling I love [you.mp3" > I wish to check them for duplicates using the script below, but theres > error msg like this "Unmatched [ in regex; marked by <-- HERE in m/only one > brace here[ <-- HERE anything.mp3/ at Untitled1 line 13." > > So how do I rewrite the regexp. > Thanks. > > ###### script ### > #!/usr/bin/perl > use strict; > use warnings; > use File::Find; > > my @datas = ("test.mp3" , "only one brace here[anything.mp3" , > "whatever.mp3"); > > while (@datas){ > my $ref = splice @datas,0,1; > foreach (@datas){ > if ($ref =~/$_/){ > print "$ref is a duplicate\n"; > }else{ > print "$ref is not a duplicate\n"; > } > } > } Escape the "special" character by using a \ so in your case you would say: "only one brace here\[anything.mp3" which the regular expression engine will translate to: "only one brace here[anything.mp3" instead of "only one brace here<Open a caracter group>anything.mp3" which would mean you never close the group and thus the regular expression is invalid and will throw an error. Regards, Rob