Izza
Izza

Reputation: 2419

Perl: Unusual RegExp

I came across this regexp in a Perl script:

$parent_file =~ s@^\Q$CurrentWorkDirForFile\E/@@

The current working directory is populated with cwd.

Can anyone please explain what this entry is?

Upvotes: 1

Views: 96

Answers (1)

Venge
Venge

Reputation: 2437

In perl, you can use (almost) any character to delimit a regex. So this is equivalent to s/^\Q$CurrentWorkDirForFile\E///. The \Q and \E disable/enable the interpretation of special pattern metacharacters. So, for example, /\Q+\E/ will match a literal plus even though + is a special character in regexps.

Upvotes: 5

Related Questions