in reply to One-liner to join keys on a two-dimensionnal hash ?
my solution:
use strict; use warnings; my %replaces = ( "foo" => { 'W100' => 'W102', 'W101' => 'W103', }, "bar" => { 'W120' => 'W99', 'W121' => 'W104', }, ); my $expr = join '|', map {keys %$_} values %replaces; print $expr;
(similar to ikegami's but DRYer)
There are multiple issues with your code:
- your data structure was buggy since it swaps ( with {
- your my $expr is scoped° to the loop, hence undef outside
- $expr = will be overwritten with each iteration
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
°) kind of, strict doesn't complain.
In Section
Seekers of Perl Wisdom