in reply to grep with color module of perl

Can't help you with a grepping module, just wanted you to know that many modern terminals support full RGB colors:

my $newfgcolor = "\e[38;2;" . join(';', $r, $g, $b) . "m"; ... my $newbgcolor = "\e[48;2;" . join(';', $r, $g, $b) . "m";

See also:

As for doing multiple matches in a program, you could just build a hash with regex+color, then iterate over over it, roughly something like this:

my %matches = ( qr/hello/ => 'FFFF00', qr/world/ => '00FF00', ... ); ... foreach my $rex (keys %matches) { if($input =~ $rex) { my ($r, $g, $b) = hex2rgb($matches{$key}); ... last; } }

Replies are listed 'Best First'.
Re^2: grep with color module of perl
by vincentaxhe (Scribe) on Aug 05, 2024 at 12:20 UTC
    much interesting stuff, terminal color things. What bothers me in the script is to find a smart way to insert color control sequence repeatly like grep did.