1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#! /opt/local/bin/perl
#
# c-c-combo-breaker!.pl
#
# TASK #2 › WORD BREAK
#
# Submitted by: Mohammad S Anwar
#
# You are given a string $S and an array of words @W.
#
# Write a script to find out if $S can be split into
# sequence of one or more words as in the given @W.
#
# Print the all the words if found otherwise print 0.
#
# EXAMPLE 1:
#
# Input:
#
# $S = "perlweeklychallenge"
# @W = ("weekly", "challenge", "perl")
#
# Output:
#
# "perl", "weekly", "challenge"
# EXAMPLE 2:
#
# Input:
#
# $S = "perlandraku"
# @W = ("python", "ruby", "haskell")
#
# Output:
#
# 0 as none matching word found.
# METHOD
#
# I have been called… things… for my love of regular
# expressions. That it wasn’t natural. Suggestions that
# there was something… off maybe, somewhere deep inside me.
# Not to discount the possibility that those people were on
# to something, I have persisted in the face of the critics.
# Refusing to be shamed, I announce it to the world. It has
# always been perhaps my favorite feature of the language,
# which is no small praise in a language with so many nice
# thing to say about it.
#
# One cannot overstate the immense power contained in the
# DSL that is Perl Regular Expressions. The added features
# of the Raku RE engine only serve to augment that power,
# and every time I have an opportunity to learn about
# something new they’ve come up with I find myself giggling
# with glee. Oh you can do that now? Sweet… Larry’s vision
# of RE really knocked it out of the park when Perl grew to
# rule the web, and the PCRE library spawned from that
# effort still holds a very promenant position today. With
# Raku, they have in a sense applied a metaoperator to the
# the very idea of regexes, expanding the initial DSL into a
# complete object ecosystem known as Grammers which we can
# in turn use to write new DSLs.* It does take a little
# getting used to coming from pure Perl, but it well worth
# the effort.
#
# This challenge, as I understand it, seems to me to be a
# straightforward application of regular expressions.
#
# ---------------
# * Andrew Shitov Creating a Complier With Raku
# https://andrewshitov.com/creating-a-compiler-with-raku/
#
#
# 2020 colin crain
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
use warnings;
use strict;
use feature ":5.26";
## ## ## ## ## MAIN:
my ($string, @words) = @ARGV;
my $group = join '|', @words;
my @matched = $string =~ m/$group/g;
say @matched ? "@matched" : 0;
|