eventual wrote:
Hi,

Hello,

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;

That is usually written as:

       my $ref = shift @datas;


       foreach (@datas){
           if ($ref =~/$_/){

That doesn't test if $ref is a duplicate, it tests if $_ is a substring of $ref, so this would print "This is a test mp3 file.html is a duplicate\n":

            if ( "This is a test mp3 file.html" =~ /test.mp3/ )

Because . will match any character and the pattern is not anchored.

If you want to see if the two strings are exactly the same then:

           if ( $ref eq $_ ) {

Or you could use a hash instead of an array so you would know that there are no duplicates.

But as to your question about the '[' character causing an error messages, you have to use quotemeta to escape regular expressions "special" characters:

           if ( $ref =~ /\Q$_/ ) {


              print "$ref is a duplicate\n";
           }else{
              print "$ref is not a duplicate\n";
           }
       }
}



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to