>From position 0 to 7 should be whatever GREP_COLOR export is defined as. There might be issues with how I'm doing that but my main issue (I think) is how I'm looping (and/or how I'm using substr).
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $line = 'foo bar baz ball'; my $match = [ [ [ '0' ], [ '7' ] ] ]; my $color = $ENV{GREP_COLOR}; # The environment looks like 1;32 but we need to send \e[32m $color =~ s/1;/\e[/; $color .= 'm'; print "match " . Dumper($match); # Each regex foreach my $ereg (@$match) { print "ereg " . Dumper(@$ereg); print "blah " . $ereg->[0][0] . "\n"; # Each match foreach my $epat (@$ereg) { print "epat " . Dumper(@$epat); substr($line, $epat->[0], 0, $color); substr($line, $epat->[1], 0, '\\e\[0m'); } } print $line ## OUT match $VAR1 = [ [ [ '0' ], [ '7' ] ] ]; ereg $VAR1 = [ '0' ]; $VAR2 = [ '7' ]; blah 0 epat $VAR1 = '0'; Use of uninitialized value in substr at ./t.pl line 36. epat $VAR1 = '7'; Use of uninitialized value in substr at ./t.pl line 36. \e\[0m\e\[0m[32mfoo bar baz ball% -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/