A Perl file I’m using contains many instances of s~. I’m not familiar with Perl and am having a hard time finding info on it. I know it’s related to a search and replace string. What does s~ do exactly?
Example:
s~ (Text)~ <a href="../images/text.pdf" target="_top">$1</a>~ig if /<p/;
>Solution :
While / is the most common delimiter, s uses whatever character immediately follows to set the delimiter to use in the rest of the expression. (This is true of many other operators, such as m, q, etc., as well.)
This example says to replace the text (Text) with an HTML anchor element, using the i and g flags.
The reason to use ~ rather than the conventional / is to avoid the need to escape the / in the replacement text, like
s/ (Text)/ <a href="..\/images\/text.pdf" target="_top">$1<\/a>/ig if /<p/;
More details can be found by running perldoc -f s.