Skip to content

Instantly share code, notes, and snippets.

Created May 11, 2017 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/cbd45272f87f9287ae56a278333c30d5 to your computer and use it in GitHub Desktop.
Save anonymous/cbd45272f87f9287ae56a278333c30d5 to your computer and use it in GitHub Desktop.
use v5.10;
my @a = (
[ 'aaa', sub { say 'Apple' } ],
[ 'bbb', sub { say 'Banana' } ],
[ 'ccc', sub { say 'Carrot' } ],
);
my @r = map {
'(' . $_->[0] . ')';
} @a;
my $r = '\G(?:' . join('|', @r) . ')';
my $i = 'aaabbbccc';
pos($i) = 3;
say "regex == /$r/";
$i =~ /$r/ or die "FAIL";
for (1..@a) {
$a[$_ - 1]->[1]->() if defined ${$_};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment