(def escape-perl-string (s) (ac-scheme:regexp-replace* "[\\\\']" s "\\\\&")) (def strperl (s) (if (ac-scheme:bytes? s) ((ac-scheme bytes-append) #"'" (escape-perl-string s) #"'") (string "'" (escape-perl-string s) "'")))
strperl
converts an Arc string to a Perl string literal that, when used in a Perl program or read with Perl’s eval
function, will result in a string in Perl that contains the same value as the original Arc string.
arc> (do (prn (strperl "What's this?")) nil) 'What\'s this?' nil
Download toperl0.arc and also get the hacks it relies on: scheme-values and ac.
Or, using the hackinator:
hack ycombinator.com/arc/arc3.1.tar awwx.ws/scheme-values0.patch awwx.ws/ac0.hack awwx.ws/toperl0.arc
This code is in the public domain.