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 !
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: One-liner to join keys on a two-dimensionnal hash ?
by johngg (Canon) on Dec 29, 2021 at 15:11 UTC | |
Re: One-liner to join keys on a two-dimensionnal hash ?
by ikegami (Patriarch) on Dec 29, 2021 at 14:44 UTC | |
by Anonymous Monk on Dec 29, 2021 at 15:01 UTC | |
by ikegami (Patriarch) on Dec 29, 2021 at 15:07 UTC | |
by eyepopslikeamosquito (Bishop) on Dec 29, 2021 at 23:20 UTC | |
Re: One-liner to join keys on a two-dimensionnal hash ?
by LanX (Sage) on Dec 29, 2021 at 15:31 UTC |
Back to
Seekers of Perl Wisdom