DavidSzczesniak
12/4/2017 - 3:41 PM

Custom Delimiters

When certain problems arise, Perl allows you to change the delimiter character to anything, as long as it's repeated at the beginning and at the end.

# A good example to showcase this would be changing the file path of a text file in a particular directory.

# Without changing delimiters, the way to do this would be just back-quoting every / and using \/ for the path separators
s/c:(\/web\/cgi-bin\/.*?.txt)/d:$1/

# Instead of this, we can use the # as the new delimiter instead of the / character
s#c:(/web/cgi-bin/.*?/txt)#d:$1#

# As another variation of this idea, we can use different pairs of delimiters around each section
s{c:(/web/cgi-bin/.*?.txt)}{d:$1}

# It's also possible to use different delimiters and put the two parts of separate lines:
s{c:(/web/cgi-bin/.*?.txt)}
(d:$1)