From 767db961a18e5033f8ecc74a6e9b3aad3f107b17 Mon Sep 17 00:00:00 2001 From: Andy Lester Date: Sun, 15 Dec 2024 11:35:42 -0600 Subject: [PATCH] Got NOT highlighting going OK --- andor.pl | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/andor.pl b/andor.pl index 5b4a546..edc3759 100644 --- a/andor.pl +++ b/andor.pl @@ -10,7 +10,7 @@ MAIN: { - my @words = @ARGV; + my @words = @ARGV or die "No words"; my @lines = ; chomp @lines; @@ -25,7 +25,7 @@ my $hl_re = join( '|', @words ); $hl_re = qr/($hl_re)/; - _iter( $match_and_re, $hl_re, @lines ); + _iter( $match_and_re, undef, $hl_re, @lines ); } OR: { @@ -37,7 +37,21 @@ my $hl_re = join( '|', @words ); $hl_re = qr/($hl_re)/; - _iter( $match_or_re, $hl_re, @lines ); + _iter( $match_or_re, undef, $hl_re, @lines ); + } + + NOT: { + say ''; + say "NOT"; + my ($keep, @not) = @words; + my $not_re; + if ( @not ) { + $not_re = join( '|', @not ); + $not_re = qr/$not_re/; + } + my $hl_re = qr/($keep)/; + + _iter( $keep, $not_re, $hl_re, @lines ); } } @@ -47,16 +61,22 @@ sub _iter { my $match_re = shift; + my $not_re = shift; my $hl_re = shift; my @lines = @_; - say "match=$match_re"; - say "hlite=$hl_re"; + say " match=$match_re"; + say " notre=", ($not_re // 'undef'); + say " hlite=$hl_re"; for ( @lines ) { my $line = "$_"; - if ( $line =~ /$match_re/ ) { + my $match = $line =~ /$match_re/; + if ( $match && defined $not_re ) { + $match = $line !~ /$not_re/; + } + if ( $match ) { while ( $line =~ /$hl_re/g ) { my $match_start = $-[0] // next; my $match_end = $+[0]; @@ -86,3 +106,5 @@ sub _iter { sox got no table and apple and penny table only +penny saved an apple +penny sat at the table