Next Tricks of the Wizards 94

Perl6::Variables

     sub translate_code {
       my $doing_a_string = shift;
       my $result = "";
       while (1) {
         if ($doing_a_string) {  # Handle backslashes
           /\G((?:\\\\)+)(?!=\\)/gc and $result .= $1, next;
           /\G((?:\\\\)+)\\./sgc and $result .= $1, next;
         }
         if (/\G([\$\@\%]) ($name) ($P) /sgcx) {
           my $arrow = "";
           my ($sigil, $var, $subs) = ($1, $2, $3);
           $arrow = "->" if $sigil eq '$';
           $result .= join "", '$', $var, $arrow, $subs;
           next;
         }
         /\G([\w\s]+)/gc and $result .= $1, next;
         /\G(.)/sgc and $result .= $1, next;
         last;
       }
       $_ = $result;
     }


Next Copyright © 2003 M. J. Dominus