note
LanX
my solution:
<c>
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;
</c><P>
(similar to ikegami's but DRYer)<P>
There are multiple issues with your code:
<UL>
<LI> your data structure was buggy since it swaps <C>(</C> with <C>{</C>
<LI> your <C>my $expr</C> is scoped° to the loop, hence <C>undef</C> outside
<LI> <C>$expr =</C> will be overwritten with each iteration
</UL><P>
<div class="pmsig"><div class="pmsig-708738">
<!--nowiki--><p>Cheers Rolf<br>
<sub>(addicted to the Perl Programming Language :)
<br> <i> [id://1153804|Wikisyntax for the Monastery]</i>
</sub>
<!--nowiki-->
</div></div><P>
°) kind of, strict doesn't complain. <!-- Wiki2Monks {"version":1.161} -->
11140005
11140005