Your problem is in this part:
push @out_array, [$r . $c];
$r . $c
concatenates the two scalars to a string. [EXPR]
creates an array reference. You don't want a reference, just plain strings:
push @out_array, $r . $c;
If you don't like push, but syntactic sugar, you can use a module that implements gather/take:
my @cross = gather {
for my $x (@A) {
for my $y (@B) {
take $x . $y;
}
}
};
This is implemented e.g. by List::Gather
or Syntax::Keyword::Gather
.
I myself am fond of elaborate map
expressions:
my @cross = map { my $x = $_; map $x.$_, @B } @A;
(same as for
with push
for all practical purposes).
Note: Perl does not have a concept of “characters” that is related to arrays. When single characters are needed, these are modelled by strings of length 1. Perl arrays always contain scalars, but for (memory) performance reasons strings are not implemented as Perl arrays, but as a pointer to a C array (of known length). The downside is different sets of operations for strings and arrays, the upside is less memory usage.
As characters are just very short strings, to join them we use standard string concatenation with .
.