http://www.perlmonks.org?node_id=1066596


in reply to Dynamically create a foreach loop within a foreach loop?

use strict; use warnings; use List::MapMulti; my %sizes = (big => 'L', small => 'S'); my %colours = (red => '001', blue => '002', black => '000'); my %origins = (American => 'US', Japanese => 'JP', German => 'DE'); my %products = (car => '0001', truck => '0004'); my @hashes = (\%sizes, \%colours, \%origins, \%products); my @hash_keys = map [sort keys %$_], @hashes; mapm { my @keys = @_; my @values = map $hashes[$_]{$_[$_]}, 0 .. $#_; my $product_desc = join q[ ], @keys; my $product_code = join q[-], @values; printf "%s - %s\n", $product_code, $product_desc; } @hash_keys;
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^2: Dynamically create a foreach loop within a foreach loop?
by PerlSufi (Friar) on Dec 11, 2013 at 15:42 UTC
    If I could vote this response more than once, I would..