Turbo Sullivan Turbo Sullivan - 2 years ago 95
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download