will work, butif ($file =~ /-\(lala\)-/) { ...
won't work. The reason is the difference where the backslash is used. In the first case it is used in a regexp, where it protects the (), while in the second one, it is used in a string where it is interpreted as a simple () used in the regexp again as capturing characters. You can use one of the following workarounds:my $skip = "/-\(lala\)-/"; if ($file =~ /$skip/)
my $skip = "/-\\(lala\\)-/"; # protect the backslash for itself if ($file =~ /$skip/) { ...
my $skip = '/-\(lala\)-/'; # use singe quotes if ($file =~ /$skip/) { ...
my $skip = "/-(lala\-/"; if ($file =~ /\Q$skip/) { ... # quote it in the regexp
my $skip = qr/-\(lala\)-/; # use precompiled regexps if ($file =~ /$skip/) { ...
Greetings,
Janek
In reply to Re: Regex matchin -(lala)- problem
by bigj
in thread Regex matchin -(lala)- problem
by sjaaq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |