Hi to all,
I have regex related pl fie below.when i execute the file it gives some error.
- #!/usr/bin/perl
-
my @array=('3242342','fdsfsd4432');
-
-
my $file='D:/HTTP/sample/SAREGAMA/HINDI/01/INH100155170 O HANSINI(ZEHREELA INSAAN.wma';
-
-
my @ee=grep(/^$file$/,@array);
-
-
print @ee;
My error
Unmatched ( in regex; marked by <-- HERE in m/^D:/HTTP/sample/SAREGAMA/HINDI/01/INH100155170 O HANSINI( <-- HERE ZEHREELA INSAAN.wma$/ at C:\DOCUME~1\INDIAM~1.COM\LOCALS~1\Temp\locB8.tmp line 9.
Please Help on this.
regards Rajiv.
Change this line:
-
my @ee=grep(/^$file$/,@array);
-
to :
-
my @ee=grep(/^\Q$file\E$/,@array);
-
In your case, $file contains forward slashes which will mess up the regex(as they stand for pattern delimiters). Even using double quotes and escaping the slashes will not work.
If you put a pattern between \Q and \E, any special meaning of the characters in pattern match will be ignored (variable substitutions will be allowed). For ex:
/\Q.*?\E/ will match '.*?'