Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi fellow monks,
I'm looking for a solution to join together all the second-level keys from a hash constructed like that :
%replaces = { "foo" => ( 'W100' => 'W102', 'W101' => 'W103', ...), "bar" => ( 'W120' => 'W99', 'W121' => 'W104', ...), ... }For instance, the hash shown below should led to the string W100|W101|W120|W121. Would it be possible to find a one-liner expression, or at least, a graceful piece of code to perform this ? I tried this :
my $expr = join '|', keys(%{$replaces{$_}}) foreach keys(%replaces);But $expr remains undefined after this line. I ended up hardcoding the expecting first-level values for the current run, but it's a dirty solution :
my $expr = join '|', (keys(%{$replaces{'foo'}}), keys(%{$replaces{'bar'}}));Thanks for any help on that !
Back to
Seekers of Perl Wisdom