Patrick R. Michaud wrote:
> On Sun, Sep 21, 2008 at 10:50:22AM -0700, Moritz Lenz via RT wrote:
>> Patrick R. Michaud wrote:
>> > It would help if someone could describe all of the things that
>> > need escaping, either as prose, Perl code, or text.
>> 
>> (CC'ed p6c and the ticket, hope it worked)
>> 
>> afaict the following characters needs escaping:
>> 
>>      \     (escaping)
>>         "     (string delimiter)
>>      $%@&  (sigils)
>>         {     (closures)
>> 
>> (assembled from http://perlcabal.org/syn/S02.html#Literals )
> 
> I tried to implement this using the .trans method on strings,
> but couldn't find the right set of arguments to pass to .trans
> (I kept getting "Must pass a List of Pairs for transliteration"
> exceptions.) 

Something along these lines?

my $x = '
$scalar
@array[]
%hash{}
&sub()
{ closure }
';

say $x.trans((
        ['\\',   '"',   '$',   '%',   '@',   '&',   '{',   "\n" ] =>
        ['\\\\', '\\"', '\\$', '\\%', '\\@', '\\&', '\\{', '\\n']
));

# prints out
[EMAIL PROTECTED]&sub()\n\{ closure }\n

Cheers,
Moritz

-- 
Moritz Lenz
http://moritz.faui2k3.org/ |  http://perl-6.de/

Reply via email to