From 35cef449575d8dc586ca8d55803836a0de720a90 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Fri, 17 Mar 2023 19:24:19 +0100 Subject: Challenge 024 task 2 --- challenge-024/jo-37/perl/ch-2.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 challenge-024/jo-37/perl/ch-2.pl 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; +} -- cgit