Skip to content

Instantly share code, notes, and snippets.

@ap
Forked from anonymous/foo.pl
Last active May 11, 2017 21:21
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 ap/9be5e786782a413494a9f115e9ec9343 to your computer and use it in GitHub Desktop.
Save ap/9be5e786782a413494a9f115e9ec9343 to your computer and use it in GitHub Desktop.
use v5.10;
use re 'eval';
my @a = (
[ 'aaa', sub { say 'Apple' } ],
[ 'bbb', sub { say 'Banana' } ],
[ 'ccc', sub { say 'Carrot' } ],
);
my @r = map {
sprintf '%s(?{%d})', $a[$_][0], $_;
} 0 .. $#a;
my $r = '\G(?:' . join('|', @r) . ')';
my $i = 'aaabbbccc';
pos($i) = 3;
say "regex == /$r/";
$i =~ /$r/ or die "FAIL";
$a[$^R]->[1]->();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment