in reply to Can map or splice replace my use of for loop + push + grep for my array transmogrification?
It has just occurred to me that the digit check might only be there because you were using a buggy for loop. If so, the solutions are much simpler.
for:
my @fulls; for my $area (@areas) { for my $short (@shorts) { push @fulls, "$short.area$area"; } }
map:
my @fulls = map { my $area = $_; map "$_.area$area", @shorts } @areas;
More intuitive map, but different order produced:
my @fulls = map { my $short = $_; map "$short.area$_", @areas } @shorts;
NestedLoops:
use Algorithm::Loops qw( NestedLoops ); my @fulls = NestedLoops( [ \@areas, \@shorts ], sub { "$_[1].area$_[0]" }, );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can map or splice replace my use of for loop + push + grep for my array transmogrification?
by jffry (Hermit) on Nov 04, 2009 at 00:30 UTC |