Is there an idiomatic way or a built-in method to concatenate two Sets
of strings?
Here's what I want:
> my Set $left = <start_ begin_>.Set
set(begin_ start_)
> my Set $right = <end finish>.Set
set(end finish)
> my Set $left_right = ($left.keys X~ $right.keys).Set
set(begin_end begin_finish start_end start_finish)
Or, if there are more than two of them:
> my Set $middle = <center_ base_>.Set
> my Set $all = ([X~] $left.keys, $middle.keys, $right.keys).Set
set(begin_base_end begin_base_finish begin_center_end begin_center_finish start_base_end start_base_finish start_center_end start_center_finish)
Perl strings are concatenated with a Dot(.) symbol. The Dot(.) sign is used instead of (+) sign in Perl.
In general, the string concatenation in Perl is very simple by using the string operator such as dot operator (.) To perform the concatenation of two operands which are declared as variables which means joining the two variables containing string to one single string using this concatenation string dot operator (.)
You can use the reduce
function to go from an arbitrary number of sets to a single set with everything concatenated in it:
my Set @sets = set(<start_ begin_>),
set(<center_ base_>),
set(<end finish>);
my $result = @sets.reduce({ set $^a.keys X~ $^b.keys });
say $result.perl
# =>
Set.new("start_base_end","begin_center_finish","start_center_finish",
"start_center_end","start_base_finish","begin_base_end",
"begin_center_end","begin_base_finish")
That seems clean to me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With