shawn wilson <ag4ve...@gmail.com> wrote:
>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

I'm unclear what you intend, but the `foreach my $epat` executes *twice*, first 
with
$epat set to [ '0' ] and then with $epat set to [ '7' ].

So in the first iteration $epat->[0] is '0' and in the second iteration it is 
'7'. In both cases there
is no $epat->[1], hence the warnings.

Perhaps what you want is $ereg->[0][0] and $ereg->[1][0]?

Rob

(Sorry about this awful email - I'm using a tablet on a train!)




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to