Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Dec 15, 2024
1 parent 1cf22fb commit 16645ef
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 36 deletions.
36 changes: 0 additions & 36 deletions and.pl

This file was deleted.

72 changes: 72 additions & 0 deletions andor.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env perl

use strict;
use warnings;
use 5.010;



MAIN: {
my @lines = <DATA>;
chomp @lines;

my @words = qw( a[pb] e$ x );

AND: {
say "AND";
my @and_parts = map { "(?=.*$_)" } @words;

my $match_and_re = join( '', @and_parts );
$match_and_re = qr/$match_and_re/;

my $hl_re = join( '|', @words );
$hl_re = qr/($hl_re)/;

_iter( $match_and_re, $hl_re, @lines );
}

OR: {
say "OR";
my $match_or_re = join( '|', @words );
$match_or_re = qr/$match_or_re/;

my $hl_re = join( '|', @words );
$hl_re = qr/($hl_re)/;

_iter( $match_or_re, $hl_re, @lines );
}
}


exit 0;


sub _iter {
my $match_re = shift;
my $hl_re = shift;
my @lines = @_;

say "match=$match_re";
say "hlite=$hl_re";

for ( @lines ) {
my $line = "$_";
if ( $line =~ /$match_re/ ) {
$line =~ s/$hl_re/[$1]/g;
say "YES: $line";
}
else {
say "NO: $line";
}
}

return;
}

__DATA__
here and there is apple
there and here is table
here is apple and table
sox got no
table and apple and penny
table only

0 comments on commit 16645ef

Please sign in to comment.