Permalink
Browse files

Escape backslashes and quotes in Str.perl (fixes #72)

  • Loading branch information...
1 parent dab6499 commit ab36838232f70cf9527d0106f14969a12e7b5d55 @sorear committed Oct 31, 2011
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/CORE.setting
View
8 lib/CORE.setting
@@ -638,8 +638,12 @@ my class Str is Cool {
} }
method gist() { defined(self) ?? self !! nextsame }
method Numeric() { Q:CgOp { (box Num (str_tonum (obj_getstr {self}))) } }
- # XXX .trans
- method perl() { defined(self) ?? '"' ~ self ~ '"' !! self.typename }
+ method perl() {
+ defined(self) // nextsame;
+ my $str = self;
+ $str ~~ s:g { <[ " \\ ]> } = '\\' ~ $/;
+ "\"$str\""
+ }
}
my class Scalar {

0 comments on commit ab36838

Please sign in to comment.