diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-17 19:24:19 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-23 18:03:43 +0100 |
| commit | 35cef449575d8dc586ca8d55803836a0de720a90 (patch) | |
| tree | 617051222960de8bee63d5909ceb00b0bbc0b44b | |
| parent | 79cfc8451bfe044aa06b36eec6fd581a47925e2b (diff) | |
| download | perlweeklychallenge-club-35cef449575d8dc586ca8d55803836a0de720a90.tar.gz perlweeklychallenge-club-35cef449575d8dc586ca8d55803836a0de720a90.tar.bz2 perlweeklychallenge-club-35cef449575d8dc586ca8d55803836a0de720a90.zip | |
Challenge 024 task 2
| -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; +} |
