in reply to I want to operate on some values in a hash
I'm averse to for ()Why? The intended meaning of map is to create a new list from an old one. So modifying a set of values with map (rather than create a new set) is considered bad practice. You might do @h{@k} = map { stuff($_) } @h{@k} if you really want to avoid a for loop, or s/stuff/other/ for @h{@k}; if it's having multiple lines that bothers you.
Edit: when I say that modifying a set of values with map is considered bad practice, I'm talking about the inplace modification of elements, as in map { $_ += 2 } @numbers;, (or the dreaded "map in void context"). @h{@k} = map { stuff($_) } @h{@k} isn't as bad, as it actually builds a temporary new list, before overwriting the values in the hash. It's just neither the most straightforward way, nor the usual way. But as long as there's no inplace editing, that's fine IMHO.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I want to operate on some values in a hash
by pwagyi (Monk) on Jan 05, 2018 at 01:49 UTC | |
|
Re^2: I want to operate on some values in a hash
by misterperl (Friar) on Jan 04, 2018 at 16:26 UTC | |
by Eily (Monsignor) on Jan 04, 2018 at 16:56 UTC | |
by karlgoethebier (Abbot) on Jan 04, 2018 at 17:24 UTC |