user2250900
user2250900

Reputation: 23

Matching $END$ in perl

When i use the line :

if (m/^$END$/g) { 
    # ...
}

in my code, the compiler thinks that I am searching for a Static'END$' in my code, whereas I want to search the string "$END$". How shall I go about it?

Upvotes: 1

Views: 113

Answers (2)

Sinan Ünür
Sinan Ünür

Reputation: 118128

if (/\A\Q $END$ /x) { ... }

perldoc perlreref:

\Q Disable pattern metacharacters until \E

Removed the /g that shouldn't be there.

Upvotes: 0

jwodder
jwodder

Reputation: 57470

To match a literal $, just escape it with a backslash:

if (m/^\$END\$/) { ... }

Removed the /g that shouldn't be there.

Upvotes: 4

Related Questions