Ashwin
Ashwin

Reputation: 13547

What is the use of Delimiter in perl regex?

What would be difference between these 2 lines of code

$bar="qwe. Aeiios qwe. Qwene. aqwet"
$bar=~/qwe/

and

$bar="qwe. Aeiios qwe. Qwene. aqwet"
    $bar=~m{qwe}

What difference does the delimiter make in the code? Both of them return true

Upvotes: 1

Views: 108

Answers (1)

Lee Duhem
Lee Duhem

Reputation: 15121

If your PATTERN includes / then /PATTERN/ may not be able to work correctly, but m{PATTERN} will. Otherwise, there is no difference between them.

According to perlop:

m/PATTERN/msixpodualgc
/PATTERN/msixpodualgc

If "/" is the delimiter then the initial m is optional. With the m you can use any pair of non-whitespace (ASCII) characters as delimiters. This is particularly useful for matching path names that contain "/", to avoid LTS (leaning toothpick syndrome).

Upvotes: 4

Related Questions