diff options
| -rwxr-xr-x | challenge-024/jo-37/perl/ch-2.pl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-024/jo-37/perl/ch-2.pl b/challenge-024/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..7b4a70c7fb --- /dev/null +++ b/challenge-024/jo-37/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use v5.16; +use warnings; +use Data::Dump; +use experimental 'postderef'; + +### Input and Output + +dd build_index(shift); + + +### Implementation + +sub build_index { + my %index; + # Match words in the input string and record all starting positions. + () = shift =~ /(\w+)(?{push $index{$^N}->@*, pos() - length($^N)})/g; + \%index; +} |
