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