Turbo Sullivan Turbo Sullivan - 5 months ago 6x
Perl Question

perl regular expressions substitue

I'm new to perl and I found this expressions bit difficult to understand

$a =~ s/\'/\'\"\'\"\'/g

Can someone help me understand what this piece of code does?


All the \ in that are useless (but harmless), so it is equivalent to s/'/'"'"'/g. It replaces every ' with '"'"' in the string.

This is often used for shell quoting. See for example http://stackoverflow.com/a/24869016/17389