Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use "s" as a substitution delimiter in Perl?

Tags:

perl

I was playing with Perl and thought that

sssssss

Would have been the same as

s/s/ss/

It seems only certain delimiters can be used. What are they?

like image 663
nowox Avatar asked May 13 '15 13:05

nowox


1 Answers

You can use any non-whitespace character as the delimiter, but you can't use the delimiter inside PATTERN or REPLACEMENT without escaping it. This is totally valid:

my $x = 's';
$x =~ s s\ss\s\ss;
print $x; # prints "ss"

Note that a space is required after the first s or else it will be interpreted as ss identifier.

like image 88
Vadim Pushtaev Avatar answered Sep 27 '22 18:09

Vadim Pushtaev