Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Dec 15, 2024
1 parent 8bbf1d6 commit 1cf22fb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions and.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env perl

use strict;
use warnings;
use 5.010;



MAIN: {
my @words = qw( apple table ^here );
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)/;
say $hl_re;

while ( my $line = <DATA> ) {
chomp $line;
if ( $line =~ /$match_and_re/ ) {
say $line;
$line =~ s/$hl_re/[$1]/g;
say $line;
}
}
}


__DATA__
here and there is apple
there and here is table
here is apple and table
table and apple and penny
table only

0 comments on commit 1cf22fb

Please sign in to comment.