Hi,

I am trying to make a program to do grep with perl6 regular expression, and I 
would like to colorize the matched part to the terminal. So the following is 
what I wrote 

sub MAIN(Str $pattern,Str $filename){
    for $filename.IO.lines -> $line  {
        my Str $temp = $line;
        if $temp ~~ s/ (<$pattern>) /\\x1b\[31m$0\\x1b\[0m/ {say $temp}; # if 
no <> surrounding $pattern it becomes literal.
    }
}

And I named the program as grep6, and I tried it in zsh as

> grep6 'M.*N' =grep6

And I got,

sub \x1b[31mMAIN\x1b[0m(Str $pattern,Str $filename){

How do I turn the string into color?

Thanks!

Xin

Reply via email to