-
-
Save opendevnet/58d2806cbfa3a2a370c3c86a026b24f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub escape ($str) { | |
# Puts a slash before non-alphanumeric characters | |
S:g[<-alpha -digit>] = "\\$/" given $str | |
} | |
say escape 'foo#bar?'; # foo\#bar\? | |
{ | |
sub escape ($str) { | |
# Writes each non-alphanumeric character in its hexadecimal escape | |
S:g[<-alpha -digit>] = "\\x[{ $/.ord.base(16) }]" given $str | |
} | |
say escape 'foo#bar?' # foo\x[23]bar\x[3F] | |
} | |
# Back to original escape function | |
say escape 'foo#bar?'; # foo\#bar\? | |
# OUTPUT: | |
# foo\#bar\? | |
# foo\x[23]bar\x[3F] | |
# foo\#bar\? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment