Skip to content

Instantly share code, notes, and snippets.

@jes

jes/numbers.pl Secret

Created August 27, 2021 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jes/c7b848220bc36d8ae3771cd77f232d0c to your computer and use it in GitHub Desktop.
Save jes/c7b848220bc36d8ae3771cd77f232d0c to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Regexp::Optimizer;
use JSON qw(from_json);
open(my $fh, '<', 'numbers.json')
or die "can't read numbers.json: $!\n";
my $c = join('',<$fh>);
close $fh;
my @numbers = @{ from_json($c)->{numbers} };
my $re = join('|',map { "^$_\$" } @numbers);
my $re2 = Regexp::Optimizer->new->optimize(qr{$re});
print "$re2\n\n\n";
while (<>) {
print if /$re2/;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment